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:
Brett Meyer 2013-06-05 18:35:36 -04:00
parent 04f3249a12
commit e2922ca5f5
13 changed files with 129 additions and 7 deletions

View File

@ -84,7 +84,8 @@
<listitem>
<para>
<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>
</listitem>
</itemizedlist>
@ -162,7 +163,8 @@
<listitem>
<para>
<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>
</listitem>
<listitem>
@ -230,7 +232,8 @@
<listitem>
<para>
<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>
</listitem>
<listitem>

View File

@ -0,0 +1 @@
/target

View File

@ -49,9 +49,10 @@
org.apache.felix.gogo.commands,
org.apache.karaf.shell.console,
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,
javassist.util.proxy,
javax.persistence;version="[1.0.0,2.1.0]",
*
</Import-Package>
<Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>

View File

@ -0,0 +1 @@
/target

View File

@ -61,9 +61,10 @@
org.apache.karaf.shell.console,
org.apache.karaf.shell.commands,
org.h2,
javax.persistence;version="[1.0.0,2.1.0]",
<!-- Needed for proxying's Javassist enhancement during runtime -->
org.hibernate.proxy,
javassist.util.proxy,
javax.persistence;version="[1.0.0,2.1.0]",
*
</Import-Package>
</instructions>

View File

@ -0,0 +1 @@
/target

View File

@ -69,9 +69,10 @@
org.hibernate,
org.hibernate.cfg,
org.hibernate.service,
javax.persistence;version="[1.0.0,2.1.0]",
<!-- Needed for proxying's Javassist enhancement during runtime -->
org.hibernate.proxy,
javassist.util.proxy,
javax.persistence;version="[1.0.0,2.1.0]",
*
</Import-Package>
</instructions>

View File

@ -37,6 +37,8 @@ public interface DataPointService {
public DataPoint get(long id);
public DataPoint load(long id);
public List<DataPoint> getAll();
public Map<Number, DefaultRevisionEntity> getRevisions(long id);

View File

@ -24,6 +24,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.hibernate.envers.AuditReader;
@ -62,6 +63,18 @@ public class DataPointServiceImpl implements DataPointService {
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() {
Session s = HibernateUtil.getSession();
s.getTransaction().begin();

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -20,6 +20,8 @@
*/
package org.hibernate.osgitest.entity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@ -31,7 +33,7 @@ import org.hibernate.envers.Audited;
*/
@Entity
@Audited
public class DataPoint {
public class DataPoint implements Serializable {
@Id
@GeneratedValue
private long id;

View File

@ -43,6 +43,16 @@
<property name="dpService" ref="dpService"/>
</action>
</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">
<action class="org.hibernate.osgitest.command.GetAllCommand">
<property name="dpService" ref="dpService"/>