[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Calling One Session From Another And Getting LazyInitializat

tlien do-not-reply at jboss.com
Wed Jan 31 16:33:57 EST 2007

I am passing an entity with a lazy loaded property from one session bean to another sessionbean and getting a LazyInitializationException. It's still inside of jboss so I don't understand why it can't load it. Is this expected behavior? If so, what is the correct way to do it. Heres a simple example of what I am talking about.

@Table(name = "LazyChild")
public class LazyChild implements java.io.Serializable {
	private Integer key;
	private String name;
	@Id @GeneratedValue
	public Integer getKey() { return key; }
	public void setKey(Integer key) { this.key = key; }
	public String getName() { return name; }
	public void setName(String s) { name = s; }

@Table(name = "Test")
public class TestEntity implements java.io.Serializable {
	private Integer key;
	private LazyChild lazyChild;
	@Id @GeneratedValue
	public Integer getKey() { return key; }
	public void setKey(Integer key) { this.key = key; }
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "LazyChildKey")
	public LazyChild getLazyChild() { return lazyChild; }
	public void setLazyChild(LazyChild l) { lazyChild = l; }

@RemoteBinding (jndiBinding="TestSessionHelper")
public class TestSessionHelperBean {
	protected EntityManager em;
	public void useLazyChild(TestEntity entity) {


@RemoteBinding (jndiBinding="TestSession")
public class TestSessionBean {
	protected EntityManager em;

	@EJB TestSessionHelper m_sessionHelper;
	public void doIt() {
		TestEntity entity = em.find(TestEntity.class, 1);


public class ClientSideTest {
	public static void main(String[] args) throws Exception {
		InitialContext ctx = new InitialContext();
		TestSession session = (TestSession)ctx.lookup("TestSession");

When I deploy these session beans and run ClientSideTest.main I get the following exception on the server side.

15:28:52,109 ERROR [LazyInitializationException] could not initialize proxy - no
org.hibernate.LazyInitializationException: could not initialize proxy - no Sessi
        at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyIn
        at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(Abstrac
        at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.intercept(CGLIBLa
        at alliancetechnical.ejb3.session.LazyChild$$EnhancerByCGLIB$$6f310ca4.g
        at alliancetechnical.ejb3.session.TestSessionHelperBean.useLazyChild(Tes
        at $Proxy670.useLazyChild(Unknown Source)
        at alliancetechnical.ejb3.session.TestSessionBean.doIt(TestSessionBean.j

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4009039#4009039

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4009039

More information about the jboss-user mailing list