Skip to content

Commit 80dc1e6

Browse files
committed
HHH-8265 Documented the reasoning for importing o.h.proxy and
javassist.util.proxy in the quickstarts. Added a load proxy test. Conflicts: documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/entity/DataPoint.java
1 parent 4a419ed commit 80dc1e6

File tree

13 files changed

+129
-4
lines changed

13 files changed

+129
-4
lines changed

documentation/src/main/docbook/devguide/en-US/chapters/osgi/OSGi.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
<listitem>
8585
<para>
8686
<literal>org.hibernate.proxy</literal> and <literal>javassist.util.proxy</literal>, due to
87-
Hibernate's ability to return proxies for lazy initialization
87+
Hibernate's ability to return proxies for lazy initialization (Javassist enhancement
88+
occurs on the entity's ClassLoader during runtime).
8889
</para>
8990
</listitem>
9091
</itemizedlist>
@@ -151,7 +152,8 @@
151152
<listitem>
152153
<para>
153154
<literal>org.hibernate.proxy</literal> and <literal>javassist.util.proxy</literal>, due to
154-
Hibernate's ability to return proxies for lazy initialization
155+
Hibernate's ability to return proxies for lazy initialization (Javassist enhancement
156+
occurs on the entity's ClassLoader during runtime)
155157
</para>
156158
</listitem>
157159
<listitem>
@@ -219,7 +221,8 @@
219221
<listitem>
220222
<para>
221223
<literal>org.hibernate.proxy</literal> and <literal>javassist.util.proxy</literal>, due to
222-
Hibernate's ability to return proxies for lazy initialization
224+
Hibernate's ability to return proxies for lazy initialization (Javassist enhancement
225+
occurs on the entity's ClassLoader during runtime)
223226
</para>
224227
</listitem>
225228
<listitem>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

documentation/src/main/docbook/quickstart/tutorials/osgi/managed-jpa/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
org.apache.felix.gogo.commands,
5050
org.apache.karaf.shell.console,
5151
org.apache.karaf.shell.commands,
52+
javax.persistence;version="[1.0.0,2.1.0]",
53+
<!-- Needed for proxying's Javassist enhancement during runtime -->
5254
org.hibernate.proxy,
5355
javassist.util.proxy,
5456
*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-jpa/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
org.apache.karaf.shell.console,
6262
org.apache.karaf.shell.commands,
6363
org.h2,
64+
javax.persistence;version="[1.0.0,2.1.0]",
65+
<!-- Needed for proxying's Javassist enhancement during runtime -->
6466
org.hibernate.proxy,
6567
javassist.util.proxy,
6668
*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
org.hibernate,
6565
org.hibernate.cfg,
6666
org.hibernate.service,
67+
javax.persistence;version="[1.0.0,2.1.0]",
68+
<!-- Needed for proxying's Javassist enhancement during runtime -->
6769
org.hibernate.proxy,
6870
javassist.util.proxy,
6971
*

documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public interface DataPointService {
3535

3636
public DataPoint get(long id);
3737

38+
public DataPoint load(long id);
39+
3840
public List<DataPoint> getAll();
3941

4042
public void deleteAll();

documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/src/main/java/org/hibernate/osgitest/DataPointServiceImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import java.util.List;
2424

25+
import org.hibernate.Hibernate;
2526
import org.hibernate.Session;
2627
import org.hibernate.criterion.Restrictions;
2728
import org.hibernate.osgitest.entity.DataPoint;
@@ -57,6 +58,18 @@ public DataPoint get(long id) {
5758
return dp;
5859
}
5960

61+
// Test lazy loading (mainly to make sure the proxy classes work in OSGi)
62+
public DataPoint load(long id) {
63+
Session s = HibernateUtil.getSession();
64+
s.getTransaction().begin();
65+
DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long(id) );
66+
// initialize
67+
dp.getName();
68+
s.getTransaction().commit();
69+
s.close();
70+
return dp;
71+
}
72+
6073
public List<DataPoint> getAll() {
6174
Session s = HibernateUtil.getSession();
6275
s.getTransaction().begin();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.hibernate.osgitest.command;
18+
19+
import org.apache.felix.gogo.commands.Action;
20+
import org.apache.felix.gogo.commands.Argument;
21+
import org.apache.felix.gogo.commands.Command;
22+
import org.apache.felix.service.command.CommandSession;
23+
import org.hibernate.osgitest.DataPointService;
24+
import org.hibernate.osgitest.entity.DataPoint;
25+
26+
@Command(scope = "dp", name = "get")
27+
public class GetCommand implements Action {
28+
@Argument(index = 0, name = "Id", required = true, description = "Id", multiValued = false)
29+
String id;
30+
31+
private DataPointService dpService;
32+
33+
public void setDpService(DataPointService dpService) {
34+
this.dpService = dpService;
35+
}
36+
37+
public Object execute(CommandSession session) throws Exception {
38+
DataPoint dp = dpService.get( Long.valueOf( id ) );
39+
System.out.println( dp.getId() + ", " + dp.getName() );
40+
return null;
41+
}
42+
43+
}

0 commit comments

Comments
 (0)