0 Replies Latest reply on Dec 25, 2009 8:31 PM by alex becker

    Transaction.rollback problem inside my jpdl

    alex becker Newbie
      Hi.
      I have a problem within my JPDL-Flow (seam 2.1.2).
      If the Persistenscontext throws an exception inside my action save(), the Transaktion was marked to rollback. After this. if i try to load a childList of my bean region.childList(), i get a lazyloading Exception (session closed),

      Can anybody help me please?
      I don't understand why the transaction was rollbacked and how should i solve the problem.
      Thanks
      alex

      The following Infos:
      1. JPDL of the flow
      2. My Parent Actionbean
      3. The Exception (inside of save: try to save the entity with null in not nullable Attribute email)
      4. The LazyloadingException

      1. JPDL:
      ==============================
      `<?xml version="1.0"?>
      <pageflow-definition xmlns="http://jboss.com/products/seam/pageflow"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://jboss.com/products/seam/pageflow http://jboss.com/products/seam/pageflow-2.1.xsd"
           name="Inserieren">
           <start-page name="inserieren" view-id="/katalog/inserieren/Inserieren.xhtml" back="enabled" >
                <transition name="chooseRegion" to="chooseRegion">
                </transition>
                <transition name="save" to="save"/>
                <transition name="cancel" to="complete" />
           </start-page>
           <decision name="save" expression="#{inserierenAction.save}">
               <transition name="true" to="complete"/>
              <transition name="false" to="inserieren"/>
           </decision>
           <page name="chooseRegion" view-id="/katalog/inserieren/ChooseRegion.xhtml"
                back="enabled" no-conversation-view-id="/katalog/inserieren/Inserieren.xhtml">
                <transition name="switchRegion" to="chooseRegion">
                     <action expression="#{chooseRegionManager.refreshDataModel}"></action>
                </transition>
                <transition name="submit" to="inserieren">
                     <action expression="#{inserierenAction.switchRegion(selectedRegion)}"></action>
                </transition>
           </page>
           <page name="complete" view-id="/katalog/inserieren/Complete.xhtml" no-conversation-view-id="/katalog/inserieren/Inserieren.xhtml">
              <end-conversation/>
              <redirect/>
           </page>
      </pageflow-definition>
      `
      2. snipped of ActionBean:
      ==============================
      `package de.company.test.session.katalog.inserieren;
      @Stateful
      @Scope(ScopeType.CONVERSATION)
      @Name("inserierenAction")
      @Synchronized
      public class InserierenActionBean implements InserierenAction {
           @PersistenceContext(type = PersistenceContextType.EXTENDED)
           private EntityManager em;
      ...
           public boolean save() {
                if (! validate()) return false;
                try {
                     em.persist(feWo);
                     return true;
                } catch (Exception e) {
                     log.info("Fehler beim Speichern des Inserats:", e);
                     facesMessages.addFromResourceBundle(
                               org.jboss.seam.international.StatusMessage.Severity.ERROR,
                               "cj.inserieren.error.save");
                     return false;

                }
           }
      }`

      3. snipped of first Exception (marks the transaktion to rollback).
      ==============================
      `2009-12-25 19:50:36,146 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] (ajp-localhost%2F127.0.0.1-8209-2) mark transaction for rollback
      2009-12-25 19:50:36,146 INFO  [de.company.test.session.katalog.inserieren.InserierenActionBean] (ajp-localhost%2F127.0.0.1-8209-2) Fehler beim Speichern des Inserats:
      Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: de.company.test.entity.FeWo.email
           at org.hibernate.engine.Nullability.checkNullability(Nullability.java:95)
           at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:313)
           at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
           at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
           at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
           at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)
           at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
           at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
           at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:645)
           at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:619)
           at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:623)
           at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220)
           ... 174 more
      2009-12-25 19:50:36,151 DEBUG [org.jboss.seam.jsf.SeamPhaseListener] (ajp-localhost%2F127.0.0.1-8209-2) rolling back transaction after phase: INVOKE_APPLICATION 5
      2009-12-25 19:50:36,155 DEBUG [org.jboss.seam.jsf.SeamPhaseListener] (ajp-localhost%2F127.0.0.1-8209-2) beginning transaction prior to phase: RENDER_RESPONSE 6
      2009-12-25 19:50:36,156 DEBUG [facelets.viewhandler] (ajp-localhost%2F127.0.0.1-8209-2) Rendering View: /katalog/inserieren/Inserieren.xhtml`

      4. snipped of exception after rollback (i think, the hibernate session was closed (rollback):
      ==============================

      `2009-12-25 19:50:46,819 DEBUG [facelets.viewhandler] (ajp-localhost%2F127.0.0.1-8209-3) Took 33ms to build view: /katalog/inserieren/ChooseRegion.xhtml
      2009-12-25 19:50:46,849 INFO  [de.company.test.session.katalog.inserieren.ChooseRegionManager] (ajp-localhost%2F127.0.0.1-8209-3) @Create initBean()
      2009-12-25 19:50:46,850 INFO  [de.company.test.session.katalog.inserieren.ChooseRegionManager] (ajp-localhost%2F127.0.0.1-8209-3) initBean() 1. Call:id[2];version[0];name[Deutschland];
      2009-12-25 19:50:46,850 INFO  [de.company.test.session.katalog.inserieren.ChooseRegionManager] (ajp-localhost%2F127.0.0.1-8209-3) getSelectedRegion:id[2];version[0];name[Deutschland];
      2009-12-25 19:50:46,850 INFO  [de.company.test.session.katalog.inserieren.ChooseRegionManager] (ajp-localhost%2F127.0.0.1-8209-3) getParentRegionSelected:null
      2009-12-25 19:50:46,850 INFO  [de.company.test.session.katalog.inserieren.ChooseRegionManager] (ajp-localhost%2F127.0.0.1-8209-3) @Factory parentRegionList
      2009-12-25 19:50:46,850 INFO  [de.company.test.session.katalog.inserieren.ChooseRegionManager] (ajp-localhost%2F127.0.0.1-8209-3) refreshDataModel regionSelection:id[2];version[0];name[Deutschland];
      2009-12-25 19:50:46,851 ERROR [org.hibernate.LazyInitializationException] (ajp-localhost%2F127.0.0.1-8209-3) failed to lazily initialize a collection of role: de.company.test.entity.Region.childElements, no session or session was closed
      org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: de.company.test.entity.Region.childElements, no session or session was closed
           at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380)
           at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372)
           at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:365)
           at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
           at org.hibernate.collection.PersistentSet.toArray(PersistentSet.java:194)
           at java.util.ArrayList.<init>(ArrayList.java:131)
           at de.company.test.session.katalog.inserieren.ChooseRegionManager.refreshDataModel(ChooseRegionManager.java:163)
           at de.company.test.session.katalog.inserieren.ChooseRegionManager.initParentRegionList(ChooseRegionManager.java:126)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
           at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
           at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.bpm.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:51)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
           at de.company.test.session.katalog.inserieren.ChooseRegionManager_$$_javassist_seam_10.initParentRegionList(ChooseRegionManager_$$_javassist_seam_10.java)
      `