HHH-8265 Documented the reasoning for importing o.h.proxy and
javassist.util.proxy in the quickstarts. Added a load proxy test.
This commit is contained in:
parent
04f3249a12
commit
e2922ca5f5
|
@ -84,7 +84,8 @@
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<literal>org.hibernate.proxy</literal> and <literal>javassist.util.proxy</literal>, due to
|
<literal>org.hibernate.proxy</literal> and <literal>javassist.util.proxy</literal>, due to
|
||||||
Hibernate's ability to return proxies for lazy initialization
|
Hibernate's ability to return proxies for lazy initialization (Javassist enhancement
|
||||||
|
occurs on the entity's ClassLoader during runtime).
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
|
@ -162,7 +163,8 @@
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<literal>org.hibernate.proxy</literal> and <literal>javassist.util.proxy</literal>, due to
|
<literal>org.hibernate.proxy</literal> and <literal>javassist.util.proxy</literal>, due to
|
||||||
Hibernate's ability to return proxies for lazy initialization
|
Hibernate's ability to return proxies for lazy initialization (Javassist enhancement
|
||||||
|
occurs on the entity's ClassLoader during runtime)
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
|
@ -230,7 +232,8 @@
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<literal>org.hibernate.proxy</literal> and <literal>javassist.util.proxy</literal>, due to
|
<literal>org.hibernate.proxy</literal> and <literal>javassist.util.proxy</literal>, due to
|
||||||
Hibernate's ability to return proxies for lazy initialization
|
Hibernate's ability to return proxies for lazy initialization (Javassist enhancement
|
||||||
|
occurs on the entity's ClassLoader during runtime)
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
|
|
1
documentation/src/main/docbook/quickstart/tutorials/osgi/managed-jpa/.gitignore
vendored
Normal file
1
documentation/src/main/docbook/quickstart/tutorials/osgi/managed-jpa/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
|
@ -49,9 +49,10 @@
|
||||||
org.apache.felix.gogo.commands,
|
org.apache.felix.gogo.commands,
|
||||||
org.apache.karaf.shell.console,
|
org.apache.karaf.shell.console,
|
||||||
org.apache.karaf.shell.commands,
|
org.apache.karaf.shell.commands,
|
||||||
|
javax.persistence;version="[1.0.0,2.1.0]",
|
||||||
|
<!-- Needed for proxying's Javassist enhancement during runtime -->
|
||||||
org.hibernate.proxy,
|
org.hibernate.proxy,
|
||||||
javassist.util.proxy,
|
javassist.util.proxy,
|
||||||
javax.persistence;version="[1.0.0,2.1.0]",
|
|
||||||
*
|
*
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
|
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
|
||||||
|
|
1
documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-jpa/.gitignore
vendored
Normal file
1
documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-jpa/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
|
@ -61,9 +61,10 @@
|
||||||
org.apache.karaf.shell.console,
|
org.apache.karaf.shell.console,
|
||||||
org.apache.karaf.shell.commands,
|
org.apache.karaf.shell.commands,
|
||||||
org.h2,
|
org.h2,
|
||||||
|
javax.persistence;version="[1.0.0,2.1.0]",
|
||||||
|
<!-- Needed for proxying's Javassist enhancement during runtime -->
|
||||||
org.hibernate.proxy,
|
org.hibernate.proxy,
|
||||||
javassist.util.proxy,
|
javassist.util.proxy,
|
||||||
javax.persistence;version="[1.0.0,2.1.0]",
|
|
||||||
*
|
*
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
</instructions>
|
</instructions>
|
||||||
|
|
1
documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/.gitignore
vendored
Normal file
1
documentation/src/main/docbook/quickstart/tutorials/osgi/unmanaged-native/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
|
@ -69,9 +69,10 @@
|
||||||
org.hibernate,
|
org.hibernate,
|
||||||
org.hibernate.cfg,
|
org.hibernate.cfg,
|
||||||
org.hibernate.service,
|
org.hibernate.service,
|
||||||
|
javax.persistence;version="[1.0.0,2.1.0]",
|
||||||
|
<!-- Needed for proxying's Javassist enhancement during runtime -->
|
||||||
org.hibernate.proxy,
|
org.hibernate.proxy,
|
||||||
javassist.util.proxy,
|
javassist.util.proxy,
|
||||||
javax.persistence;version="[1.0.0,2.1.0]",
|
|
||||||
*
|
*
|
||||||
</Import-Package>
|
</Import-Package>
|
||||||
</instructions>
|
</instructions>
|
||||||
|
|
|
@ -37,6 +37,8 @@ public interface DataPointService {
|
||||||
|
|
||||||
public DataPoint get(long id);
|
public DataPoint get(long id);
|
||||||
|
|
||||||
|
public DataPoint load(long id);
|
||||||
|
|
||||||
public List<DataPoint> getAll();
|
public List<DataPoint> getAll();
|
||||||
|
|
||||||
public Map<Number, DefaultRevisionEntity> getRevisions(long id);
|
public Map<Number, DefaultRevisionEntity> getRevisions(long id);
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
import org.hibernate.envers.AuditReader;
|
import org.hibernate.envers.AuditReader;
|
||||||
|
@ -62,6 +63,18 @@ public class DataPointServiceImpl implements DataPointService {
|
||||||
return dp;
|
return dp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test lazy loading (mainly to make sure the proxy classes work in OSGi)
|
||||||
|
public DataPoint load(long id) {
|
||||||
|
Session s = HibernateUtil.getSession();
|
||||||
|
s.getTransaction().begin();
|
||||||
|
DataPoint dp = (DataPoint) s.load( DataPoint.class, new Long(id) );
|
||||||
|
// initialize
|
||||||
|
dp.getName();
|
||||||
|
s.getTransaction().commit();
|
||||||
|
s.close();
|
||||||
|
return dp;
|
||||||
|
}
|
||||||
|
|
||||||
public List<DataPoint> getAll() {
|
public List<DataPoint> getAll() {
|
||||||
Session s = HibernateUtil.getSession();
|
Session s = HibernateUtil.getSession();
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Argument;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "get")
|
||||||
|
public class GetCommand implements Action {
|
||||||
|
@Argument(index = 0, name = "Id", required = true, description = "Id", multiValued = false)
|
||||||
|
String id;
|
||||||
|
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
DataPoint dp = dpService.get( Long.valueOf( id ) );
|
||||||
|
System.out.println( dp.getId() + ", " + dp.getName() );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.hibernate.osgitest.command;
|
||||||
|
|
||||||
|
import org.apache.felix.gogo.commands.Action;
|
||||||
|
import org.apache.felix.gogo.commands.Argument;
|
||||||
|
import org.apache.felix.gogo.commands.Command;
|
||||||
|
import org.apache.felix.service.command.CommandSession;
|
||||||
|
import org.hibernate.osgitest.DataPointService;
|
||||||
|
import org.hibernate.osgitest.entity.DataPoint;
|
||||||
|
|
||||||
|
@Command(scope = "dp", name = "load")
|
||||||
|
public class LoadCommand implements Action {
|
||||||
|
@Argument(index = 0, name = "Id", required = true, description = "Id", multiValued = false)
|
||||||
|
String id;
|
||||||
|
|
||||||
|
private DataPointService dpService;
|
||||||
|
|
||||||
|
public void setDpService(DataPointService dpService) {
|
||||||
|
this.dpService = dpService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(CommandSession session) throws Exception {
|
||||||
|
DataPoint dp = dpService.load( Long.valueOf( id ) );
|
||||||
|
System.out.println( dp.getId() + ", " + dp.getName() );
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -20,6 +20,8 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.osgitest.entity;
|
package org.hibernate.osgitest.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
@ -31,7 +33,7 @@ import org.hibernate.envers.Audited;
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Audited
|
@Audited
|
||||||
public class DataPoint {
|
public class DataPoint implements Serializable {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
private long id;
|
private long id;
|
||||||
|
|
|
@ -43,6 +43,16 @@
|
||||||
<property name="dpService" ref="dpService"/>
|
<property name="dpService" ref="dpService"/>
|
||||||
</action>
|
</action>
|
||||||
</command>
|
</command>
|
||||||
|
<command name="dp:get">
|
||||||
|
<action class="org.hibernate.osgitest.command.GetCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
|
<command name="dp:load">
|
||||||
|
<action class="org.hibernate.osgitest.command.LoadCommand">
|
||||||
|
<property name="dpService" ref="dpService"/>
|
||||||
|
</action>
|
||||||
|
</command>
|
||||||
<command name="dp:getAll">
|
<command name="dp:getAll">
|
||||||
<action class="org.hibernate.osgitest.command.GetAllCommand">
|
<action class="org.hibernate.osgitest.command.GetAllCommand">
|
||||||
<property name="dpService" ref="dpService"/>
|
<property name="dpService" ref="dpService"/>
|
||||||
|
|
Loading…
Reference in New Issue