3 Replies Latest reply on Jun 3, 2008 10:58 PM by Olivier D

    Multiple persist in the same request !

    Olivier D Newbie

      Hi there,


      I have a problem to persist multiple instances of an Entity in the same request.


      It works fine when i persist each instance at a time


      Best regards,


      Olivier D

        • 1. Re: Multiple persist in the same request !
          Joshua Jackson Master

          Show us your java action code here.


          Did you mark your method with @Transactional ?

          • 2. Re: Multiple persist in the same request !
            Ben Swenka Newbie

            Have you tried passing the entity to entityManager.persist(entity); ?

            • 3. Re: Multiple persist in the same request !
              Olivier D Newbie

              Hi !


              Here are java code and stack trace.


              Entity


              
              @Entity
              
              @Table(uniqueConstraints = @UniqueConstraint(columnNames = "email"))
              
              public class InviteFriend implements Serializable {
              
                 private static final long serialVersionUID = xxxxxxxxxxx;
              
              
                 @Id @GeneratedValue
              
                 private Integer inviteId;
              
                 private Date sentDate;
              
                 private Boolean accepted;
              
                 
              
                 @NotNull @Email    
              
                 private String email;
              
                 @Lob
              
                 @Basic(fetch=FetchType.LAZY)
              
                 @Length(min = 0, max = 1000)
              
                 private String message;      
              
                 @ManyToOne(fetch = FetchType.LAZY)
              
                 @JoinColumn(name = "MEMBER_ID")   
              
                 private Member member;
              
                 @ManyToOne(fetch = FetchType.LAZY)
              
                 @JoinColumn(name = "NETWORK_ID")   
              
                 private Network network;
              
              
              .....................
              
              
              }
              
              



              java DAO method


              
              public void createInviteFriend(InviteFriend frd) {
              
                  
              
              try {                                    
              
                  entityManager.persist(frd);  
              
                   }
              
              catch(Exception ex) { }          
              
              
              }    
              
              
              



              java action method


              
              public void inviteMember() {
              
              
                for (Iterator iter = frdList.iterator(); iter.hasNext();) {   
              
              
                 InviteFriend frd = (InviteFriend)iter.next();
              
              
                 memberDAO.createInviteFriend(frd);
              
                      
              
                }
              
                 
              
              }
              
              
              



              and the stack trace !


              
              22:23:29,812 ERROR [AssertionFailure] an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
              
              org.hibernate.AssertionFailure: null id in com.pixarus.entity.InviteFriend entry (don't flush the Session after an exception occurs)
              
                   at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55)
              
                   at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:164)
              
                   at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
              
                   at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
              
                   at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
              
                   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
              
                   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
              
                   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
              
                   at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
              
                   at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
              
                   at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
              
                   at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
              
                   at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
              
                   at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1382)
              
                   at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
              
                   at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
              
                   at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)
              
                   at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
              
                   at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:603)
              
                   at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:341)
              
                   at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:241)
              
                   at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:192)
              
                   at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
              
                   at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
              
                   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
              
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              
                   at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
              
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              
                   at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              
                   at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
              
                   at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:503)
              
                   at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
              
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              
                   at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
              
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              
                   at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              
                   at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
              
                   at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:256)
              
                   at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:362)
              
                   at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:488)
              
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              
                   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              
                   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
              
                   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              
                   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
              
                   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
              
                   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
              
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
              
                   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
              
                   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
              
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              
                   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
              
                   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              
                   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
              
                   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
              
                   at java.lang.Thread.run(Unknown Source)
              
              




              Where am i wrong ?


              Thanks


              Olivier