1 Reply Latest reply on Jun 26, 2006 2:37 PM by Tamir Efron

    @OneToMany fails with FetchType.LAZY

    Hauke Stange Newbie

      Hi there,

      everytime I try to fetch a OneToMany-Mapped collection of the type list it fails.

      By invoking the customer's getEmails() method, I get the following exception which I don't understand really.


      Maybe someone of you can help me with that.


      Regards,
      Hauke


      JBoss: 4.0.4.GA
      Hibernate: 3.2.0.cr2
      Hibernate Annotations: 3.2.0.CR1
      Hibernate EntityManager: 3.2.0.CR1




      org.hibernate.LazyInitializationException

      26.06.2006 20:04:13 org.hibernate.LazyInitializationException <init>
      SCHWERWIEGEND: failed to lazily initialize a collection of role: plyd.model.customer.CustomerAccount.emails, no session or session was closed
      org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: plyd.model.customer.CustomerAccount.emails, no session or session was closed
       at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
       at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
       at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
       at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
       at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:246)
       at plyd.customer.customer.ShowPersonalDetailsPanel.setBean(ShowPersonalDetailsPanel.java:283)
       at plyd.customer.ManageCustomerPanel.setCustomer(ManageCustomerPanel.java:105)
       at plyd.customer.search.SearchCustomerAction.actionPerformed(SearchCustomerAction.java:60)
       at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
       at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
       at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
       at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
       at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
       at java.awt.Component.processMouseEvent(Component.java:5488)
       at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
       at java.awt.Component.processEvent(Component.java:5253)
       at java.awt.Container.processEvent(Container.java:1966)
       at java.awt.Component.dispatchEventImpl(Component.java:3955)
       at java.awt.Container.dispatchEventImpl(Container.java:2024)
       at java.awt.Component.dispatchEvent(Component.java:3803)
       at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
       at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
       at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
       at java.awt.Container.dispatchEventImpl(Container.java:2010)
       at java.awt.Window.dispatchEventImpl(Window.java:1774)
       at java.awt.Component.dispatchEvent(Component.java:3803)
       at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
       at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
       at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
       at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
      Exception in thread "AWT-EventQueue-0" org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: plyd.model.customer.CustomerAccount.emails, no session or session was closed
       at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
       at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
       at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
       at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
       at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:246)
       at plyd.customer.customer.ShowPersonalDetailsPanel.setBean(ShowPersonalDetailsPanel.java:283)
       at plyd.customer.ManageCustomerPanel.setCustomer(ManageCustomerPanel.java:105)
       at plyd.customer.search.SearchCustomerAction.actionPerformed(SearchCustomerAction.java:60)
       at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
       at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
       at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
       at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
       at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
       at java.awt.Component.processMouseEvent(Component.java:5488)
       at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
       at java.awt.Component.processEvent(Component.java:5253)
       at java.awt.Container.processEvent(Container.java:1966)
       at java.awt.Component.dispatchEventImpl(Component.java:3955)
       at java.awt.Container.dispatchEventImpl(Container.java:2024)
       at java.awt.Component.dispatchEvent(Component.java:3803)
       at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
       at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
       at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
       at java.awt.Container.dispatchEventImpl(Container.java:2010)
       at java.awt.Window.dispatchEventImpl(Window.java:1774)
       at java.awt.Component.dispatchEvent(Component.java:3803)
       at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
       at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
       at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
       at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
      
      


      CustomerAccount Bean

      @Entity
      public class CustomerAccount implements Serializable {
      
       @Id
       @GeneratedValue
       protected long id;
      
       @OneToMany( cascade = CascadeType.ALL )
       protected List<CustomerEMail> emails;
      
      
       public CustomerAccount() {
       super();
       }
      
       public long getId() {
       return id;
       }
      
       public List<CustomerEMail> getEmails() {
       if (emails == null) {
       emails = new ArrayList<CustomerEMail>();
       }
       return emails;
       }
      
       public void setEmails(List<CustomerEMail> emails) {
       this.emails = emails;
       }
      
      }
      


      CustomerEMail Bean

      @Entity
      public class CustomerEMail implements Serializable {
      
       @Id
       @GeneratedValue
       protected long id;
      
       protected String email;
      
       @Temporal( TemporalType.DATE )
       protected Date created;
      
       @Temporal( TemporalType.DATE )
       protected Date verified;
      
       public CustomerEMail() {
       super();
       }
      
       public Date getCreated() {
       return created;
       }
      
       public void setCreated(Date created) {
       this.created = created;
       }
      
       public String getEmail() {
       return email;
       }
      
       public void setEmail(String mail) {
       email = mail;
       }
      
       public long getId() {
       return id;
       }
      
       public Date getVerified() {
       return verified;
       }
      
       public void setVerified(Date verified) {
       this.verified = verified;
       }
      
      }