4 Replies Latest reply on Nov 15, 2005 2:41 PM by kk null

    lazy initialization and @PersistenceContext(EXTENDED)

    kk null Newbie

      I have a couple of annotated classes deployed, a stateful bean and a client (web), running on jboss-4.0.3SP1

      stateful bean declaration as follows:

      public class TestBeanImpl implements TestBean {
       @PersistenceContext(type = PersistenceContextType.EXTENDED)
       EntityManager em;
       public X businessMethod() {
       return em.createQuery("").getSingleResult();

      Entity X contains a collection, that fails to lazily initialize in this test:

       InitialContext ctx = new InitialContext();
       TestBean testBean = (TestBean)ctx.lookup(TestBean.class.getName());
       X x = testBean.businessMethod();
       List l = x.getList();
       Y y = (Y)l.get(0);

      The last line throws an exception: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role:

      What am I doing wrong?