1 2 Previous Next 22 Replies Latest reply on Nov 23, 2005 5:24 PM by svetsch

    Using saveOrUpdate()

    nusa

      Hi,

      When I invoke the saveOrUpdate() method, it looks like nothing is persisted.
      Here is a portion of the code :

      ...
      @In(create=true)
      private Session hibernateSession;
      ...
      log.info("=== Attempting to update a row : " + prj.toString());
      hibernateSession.saveOrUpdate(prj);
      ...
      


      And here is the log :
      15:33:46,886 INFO [example.action.ProjectAction] === Attempting to update a row : Project ( p1 0 Project1 Project1 by baa test
      
      )15:33:46,896 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] persistent instance of: example.model.Project15:33:46,896 DEBUG
      
      [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] ignoring persistent instance15:33:46,896 DEBUG
      
      [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] object already associated with session: [example.model.Project#p1]15:33:46,896
      
      DEBUG [com.sun.faces.lifecycle.InvokeApplicationPhase] Exiting InvokeApplicationsPhase


      What am I missing here ? Can I still use that method instead of em.persist() ?

      The other thing is I found this warning :
      15:42:26,800 WARN [org.hibernate.jdbc.ConnectionManager] unclosed connection, forgot to call close() on your session?
      

      Where do I have to close() my session ?

      Any help/suggestions would be agreat.


      Thanks.

        • 1. Re: Using saveOrUpdate()
          gavin.king

          You should not have to close the session explicitly, assuming you are using SeamExtendedManagedPersistencePhaseListener. Are you still seeing this log message?

          • 2. Re: Using saveOrUpdate()
            nusa

             

            "gavin.king@jboss.com" wrote:
            You should not have to close the session explicitly, assuming you are using SeamExtendedManagedPersistencePhaseListener. Are you still seeing this log message?


            Gavin,

            I'm using it, as defined in my faces-config :

            <lifecycle>
            <phase-listener>org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener</phase-listener>
            </lifecycle>
            


            I just don't get it :
            1. why saveOrUpdate() did not persist my object.
            2. it would be nice if I don't get that warning.

            Any idea ?

            Thanks.

            • 3. Re: Using saveOrUpdate()
              gavin.king

              It really sounds to me like the phase listener is not being called. Please show me a debug level seam log. There should be log messages like "beginning transaction", "committing transaction".

              • 4. Re: Using saveOrUpdate()
                nusa

                 

                "gavin.king@jboss.com" wrote:
                It really sounds to me like the phase listener is not being called. Please show me a debug level seam log. There should be log messages like "beginning transaction", "committing transaction".


                OK, here is the log :
                14:36:04,951 DEBUG [org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener] beginning transaction
                14:36:04,951 DEBUG [com.sun.faces.lifecycle.UpdateModelValuesPhase] Entering UpdateModelValuesPhase
                14:36:04,961 DEBUG [org.jboss.seam.jsf.SeamVariableResolver] resolving name: row
                14:36:04,961 DEBUG [org.jboss.seam.Component] seam component not found: row
                14:36:04,961 DEBUG [com.sun.faces.el.VariableResolverImpl] resolveVariable: Resolved variable:Project ( p1 0 Project1 Project1 by baa )
                14:36:04,961 DEBUG [org.jboss.seam.jsf.SeamVariableResolver] resolved name to managed bean
                14:36:04,961 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(INVOKE_APPLICATION 5,com.sun.faces.context.FacesContextImpl@766e80)
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                14:36:04,961 DEBUG [com.sun.faces.lifecycle.InvokeApplicationPhase] Entering InvokeApplicationsPhase
                14:36:04,961 DEBUG [com.sun.faces.application.ActionListenerImpl] processAction(_id24)
                14:36:04,961 DEBUG [com.sun.faces.el.ValueBindingImpl] getValue(ref=projectAction)
                14:36:04,961 DEBUG [org.jboss.seam.jsf.SeamVariableResolver] resolving name: projectAction
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: projectAction
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: projectAction.component
                14:36:04,961 DEBUG [com.sun.faces.application.ApplicationImpl] Couldn't find a factory for projectAction
                14:36:04,961 DEBUG [com.sun.faces.el.VariableResolverImpl] resolveVariable: Resolved variable:null
                14:36:04,961 DEBUG [org.jboss.seam.jsf.SeamVariableResolver] resolved name to seam component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: projectAction.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                14:36:04,961 DEBUG [example.action.LoggedInInterceptor] User is already logged in
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: facesContext
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: facesContext.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in conversation context: hibernateSession
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: hibernateSession.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: project.component
                14:36:04,961 DEBUG [com.sun.faces.el.ValueBindingImpl] getValue Result:example.action.ProjectAction$$EnhancerByCGLIB$$270b8444@c08c5
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: projectAction.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                14:36:04,961 DEBUG [example.action.LoggedInInterceptor] User is already logged in
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: facesContext
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: facesContext.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in conversation context: hibernateSession
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: hibernateSession.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: project.component
                14:36:04,961 DEBUG [com.sun.faces.el.ValueBindingImpl] -->Returning example.action.ProjectAction$$EnhancerByCGLIB$$270b8444@c08c5
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: projectAction.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                14:36:04,961 DEBUG [example.action.LoggedInInterceptor] User is already logged in
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: facesContext
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: facesContext.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in conversation context: hibernateSession
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: hibernateSession.component
                14:36:04,961 INFO [example.action.ProjectAction] === markForEdition ...
                14:36:04,961 INFO [example.action.ProjectAction] === get dataAction ...
                14:36:04,961 INFO [example.action.ProjectAction] === The obj is example.action.DataAction$$EnhancerByCGLIB$$c24cc8fd
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: dataAction.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                14:36:04,961 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                14:36:04,961 INFO [example.action.DataAction] === getTable ...
                14:36:04,961 INFO [example.action.ProjectAction] === Iterator ...
                14:36:04,961 INFO [example.action.ProjectAction] === oldKey : 0
                14:36:04,961 INFO [example.action.ProjectAction] === Attempting to update a row : Project ( p1 0 Project1 Project1 by baa test )
                14:36:04,971 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] persistent instance of: example.model.Project
                14:36:04,971 DEBUG [org.hibernate.event.def.DefaultMergeEventListener] ignoring persistent instance
                14:36:04,971 DEBUG [org.hibernate.engine.Cascade] processing cascade ACTION_MERGE for: example.model.Project
                14:36:04,971 DEBUG [org.hibernate.engine.Cascade] cascade ACTION_MERGE for collection: example.model.Project.timesheets
                14:36:04,971 DEBUG [org.hibernate.engine.Cascade] done cascade ACTION_MERGE for collection: example.model.Project.timesheets
                14:36:04,971 DEBUG [org.hibernate.engine.Cascade] cascade ACTION_MERGE for collection: example.model.Project.employees
                14:36:04,971 DEBUG [org.hibernate.engine.Cascade] done cascade ACTION_MERGE for collection: example.model.Project.employees
                14:36:04,971 DEBUG [org.hibernate.engine.Cascade] done processing cascade ACTION_MERGE for: example.model.Project
                14:36:04,971 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: project.component
                14:36:04,971 DEBUG [com.sun.faces.lifecycle.InvokeApplicationPhase] Exiting InvokeApplicationsPhase
                14:36:04,971 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                14:36:04,971 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                14:36:04,971 DEBUG [org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener] committing transaction
                



                I tried as well with merge(), but it didn't persisted.

                Thanks.

                • 5. Re: Using saveOrUpdate()
                  gavin.king

                  According to the log, the instance you passed to saveOrUpdate() is actually persistent, which means that there is absolutely no need to call saveOrUpdate().

                  It also looks like you cut off the log too early. I'm expecting to see log messages from Hibernate right after this line:

                  14:36:04,971 DEBUG [org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener] committing trans
                  action

                  • 6. Re: Using saveOrUpdate()
                    gavin.king

                    BTW, make sure you have this stuff in your hibernate.cfg.xml, just like in the noejb example:

                    true
                    after_statement
                    org.hibernate.transaction.JBossTransactionManagerLookup
                    org.hibernate.transaction.JTATransactionFactory

                    • 7. Re: Using saveOrUpdate()
                      gavin.king

                      I mean:


                      true
                      after_statement
                      org.hibernate.transaction.JBossTransactionManagerLookup
                      org.hibernate.transaction.JTATransactionFactory

                      • 8. Re: Using saveOrUpdate()
                        gavin.king

                        true
                        after_statement
                        org.hibernate.transaction.JBossTransactionManagerLookup
                        org.hibernate.transaction.JTATransactionFactory



                        • 9. Re: Using saveOrUpdate()
                          gavin.king

                          If this doesn't work, I give up :(

                          <property name="transaction.flush_before_completion">true</property>
                           <property name="connection.release_mode">after_statement</property>
                           <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
                           <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
                          
                          


                          • 10. Re: Using saveOrUpdate()
                            nusa

                             

                            "gavin.king@jboss.com" wrote:
                            If this doesn't work, I give up :(

                            <property name="transaction.flush_before_completion">true</property>
                             <property name="connection.release_mode">after_statement</property>
                             <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
                             <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
                            
                            


                            Maybe I should give you more information.

                            My Hibernate config is almost similar to the examples :
                            ...
                             <property name="transaction.flush_before_completion">true</property>
                             <property name="connection.release_mode">after_statement</property>
                            
                             <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
                             <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
                            ...
                            


                            The action listener is defined as :
                            @Intercept(InterceptionType.ALWAYS)
                            @LoggedIn
                            @Name("projectAction")
                            public class ProjectAction {
                             ...
                             @Out(required=false)
                             @Valid
                             private Project project;
                            
                             private List<Project> listProject;
                            
                             @In(create=true)
                             private Session hibernateSession;
                            
                             public List<Project> getFindAll() {
                             log.info("=== getFindAll ... ");
                             if (listProject == null)
                             buildListProject();
                             return listProject;
                             }
                            
                             public void setFindAll(List<Project> prj) {
                             this.listProject = prj;
                             }
                            
                             @SuppressWarnings("unchecked")
                             public void buildListProject() {
                             log.info("=== buildListProject ... ");
                             List<Project> list = null;
                             try {
                             list = hibernateSession.createCriteria(Project.class)
                             .addOrderOrder.asc"projectName"))
                             .list();
                             log.info("=== buildListProject has : " + list.size());
                             } catch (HibernateException ex) {
                             throw new TestSeamException("HibernateException raised : " + ex.toString());
                             }
                             setFindAll(list);
                             }
                            
                             @IfInvalid(outcome=REDISPLAY)
                             public String markForEdition() {
                             log.info("=== markForEdition ...");
                             ...
                             if ( table.isRowAvailable() ) {
                             project = (Project) table.getRowData();
                             log.info("=== Attempting to update a row : " + project.toString());
                            
                             // Try this, but not working !
                             //hibernateSession.saveOrUpdate(project);
                            
                             // Try this, but not working !
                             //project = (Project)hibernateSession.merge(project);
                            
                             hibernateSession.update(project);
                             return "success";
                             } else {
                             log.info("=== Couldn't find row !!!");
                             msg = MessageFactory.getMessage(facesContext ,"NoUpdate");
                             facesContext.addMessage(null, msg);
                             }
                            
                             return null;
                             }
                            }
                            


                            For the log, there are quite a number of 'beginning transaction' and 'commiting transaction' :
                            ...(1)
                            10:35:26,866 DEBUG [org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener] committing transaction
                            10:35:26,866 DEBUG [org.hibernate.transaction.CacheSynchronization] transaction before completion callback
                            10:35:26,866 DEBUG [org.hibernate.transaction.CacheSynchronization] automatically flushing session
                            10:35:26,866 DEBUG [org.hibernate.impl.SessionImpl] automatically flushing session
                            10:35:26,866 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] flushing session
                            10:35:26,866 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] processing flush-time cascades
                            10:35:26,876 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] dirty checking collections
                            10:35:26,876 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] Flushing entities and processing referenced collections
                            10:35:26,886 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] Processing unreferenced collections
                            10:35:26,886 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] Scheduling collection removes/(re)creates/updates
                            10:35:26,886 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
                            10:35:26,886 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
                            10:35:26,886 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] executing flush
                            10:35:26,886 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] post flush
                            10:35:26,886 DEBUG [org.hibernate.jdbc.JDBCContext] before transaction completion
                            10:35:26,886 DEBUG [org.hibernate.impl.SessionImpl] before transaction completion
                            10:35:26,886 DEBUG [org.hibernate.transaction.CacheSynchronization] transaction after completion callback, status: 3
                            10:35:26,886 DEBUG [org.hibernate.jdbc.JDBCContext] after transaction completion
                            10:35:26,886 DEBUG [org.hibernate.impl.SessionImpl] after transaction completion
                            10:35:26,886 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] render(com.sun.faces.context.FacesContextImpl@1a437b6)
                            10:35:26,896 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] execute(com.sun.faces.context.FacesContextImpl@dd3147)
                            10:35:26,896 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(RESTORE_VIEW 1,com.sun.faces.context.FacesContextImpl@dd3147)
                            10:35:26,896 DEBUG [org.jboss.seam.contexts.Lifecycle] >>> Begin web request
                            ...(2)
                            10:35:52,013 INFO [example.action.ProjectAction] === markForEdition ...
                            10:35:52,013 INFO [example.action.ProjectAction] === get dataAction ...
                            10:35:52,013 INFO [example.action.ProjectAction] === The obj is example.action.DataAction$$EnhancerByCGLIB$$c24cc8fd
                            10:35:52,013 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: dataAction.component
                            10:35:52,013 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                            10:35:52,013 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                            10:35:52,013 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                            10:35:52,013 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                            10:35:52,013 INFO [example.action.DataAction] === getTable ...
                            10:35:52,013 INFO [example.action.ProjectAction] === Attempting to update a row : Project ( p1 0 Project1 Project1 by baa is modified )
                            10:35:52,023 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] ignoring persistent instance
                            10:35:52,023 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] object already associated with session: [example.model.Project#p1]
                            10:35:52,023 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: project.component
                            10:35:52,023 DEBUG [com.sun.faces.lifecycle.InvokeApplicationPhase] Exiting InvokeApplicationsPhase
                            10:35:52,023 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                            10:35:52,023 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                            10:35:52,023 DEBUG [org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener] committing transaction
                            10:35:52,023 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] render(com.sun.faces.context.FacesContextImpl@1395750)
                            10:35:52,023 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@1395750)
                            10:35:52,023 DEBUG [org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener] beginning transaction
                            10:35:52,023 DEBUG [org.jboss.seam.jsf.SeamPhaseListener] Before render response
                            10:35:52,023 DEBUG [org.jboss.seam.contexts.Contexts] found in event context: org.jboss.seam.core.manager
                            10:35:52,023 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.manager.component
                            ...(3)
                            10:35:52,063 INFO [example.action.ProjectAction] === getFindAll ...
                            10:35:52,063 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: project.component
                            10:35:52,063 DEBUG [com.sun.faces.el.ValueBindingImpl] getValue Result:[Project ( p1 0 Project1 Project1 by baa is modified ), Project ( p2 0 Project2 Project2 by emp1 ), Project ( p3 0 Project3 Project3 by emp5 )]
                            10:35:52,063 DEBUG [com.sun.faces.el.ValueBindingImpl] -->Returning [Project ( p1 0 Project1 Project1 by baa is modified ), Project ( p2 0 Project2 Project2 by emp1 ), Project ( p3 0 Project3 Project3 by emp5 )]
                            ...(4)
                            10:35:52,083 DEBUG [org.jboss.seam.contexts.Lifecycle] <<< End web request
                            10:35:52,083 DEBUG [org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener] committing transaction
                            10:36:07,506 DEBUG [org.hibernate.jdbc.ConnectionManager] running Session.finalize()
                            10:36:21,056 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] execute(com.sun.faces.context.FacesContextImpl@10cf62)
                            10:36:21,056 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(RESTORE_VIEW 1,com.sun.faces.context.FacesContextImpl@10cf62)
                            ...(5)
                            10:36:21,076 INFO [example.action.ProjectAction] === getFindAll ...
                            10:36:21,076 INFO [example.action.ProjectAction] === buildListProject ...
                            10:36:21,076 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
                            10:36:21,076 DEBUG [org.hibernate.jdbc.ConnectionManager] opening JDBC connection
                            10:36:21,076 DEBUG [org.hibernate.jdbc.JDBCContext] no active transaction, could not register Synchronization
                            
                            10:36:21,076 DEBUG [org.hibernate.SQL]
                             select
                             this_.projectId as projectId7_0_,
                             this_.version as version7_0_,
                             this_.descriptions as descript3_7_0_,
                             this_.projectName as projectN4_7_0_
                             from
                             Project this_
                             order by
                             this_.projectName asc
                            10:36:21,076 INFO [STDOUT] Hibernate:
                             select
                             this_.projectId as projectId7_0_,
                             this_.version as version7_0_,
                             this_.descriptions as descript3_7_0_,
                             this_.projectName as projectN4_7_0_
                             from
                             Project this_
                             order by
                             this_.projectName asc
                            10:36:21,076 DEBUG [org.hibernate.jdbc.AbstractBatcher] preparing statement
                            10:36:21,076 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open ResultSet (open ResultSets: 0, globally: 0)
                            10:36:21,076 DEBUG [org.hibernate.loader.Loader] processing result set
                            10:36:21,076 DEBUG [org.hibernate.loader.Loader] result set row: 0
                            10:36:21,076 DEBUG [org.hibernate.type.StringType] returning 'p1' as column: projectId7_0_
                            10:36:21,076 DEBUG [org.hibernate.loader.Loader] result row: EntityKey[example.model.Project#p1]
                            10:36:21,076 DEBUG [org.hibernate.loader.Loader] Initializing object from ResultSet: [example.model.Project#p1]
                            10:36:21,076 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] Hydrating entity: [example.model.Project#p1]
                            10:36:21,076 DEBUG [org.hibernate.type.IntegerType] returning '0' as column: version7_0_
                            10:36:21,076 DEBUG [org.hibernate.type.StringType] returning 'Project1 by baa' as column: descript3_7_0_
                            10:36:21,076 DEBUG [org.hibernate.type.StringType] returning 'Project1' as column: projectN4_7_0_
                            10:36:21,076 DEBUG [org.hibernate.engine.TwoPhaseLoad] Version: 0
                            


                            (1) : JSF pages are called prior to ProjectAction
                            (2) : We are in ProjectAction. I modified the 'p1' row into 'Project1 by baa is modified'
                            (3) : The row modified is 'persisted'
                            (4) : Commit the transaction
                            (5) : I refresh the JSP page, Hibernate reload from the database, but 'p1' is 'rollbacked' into 'Project1 by baa',
                            instead of 'Project1 by baa is modified'

                            What am I missing in the code above ?

                            • 11. Re: Using saveOrUpdate()
                              nusa

                               

                              "gavin.king@jboss.com" wrote:
                              If this doesn't work, I give up :(

                              <property name="transaction.flush_before_completion">true</property>
                               <property name="connection.release_mode">after_statement</property>
                               <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
                               <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
                              
                              


                              If I declare as above, i.e.:
                               @Out(required=false)
                               @Valid
                               private Project project;
                              

                              the row that I modified do not get 'persisted' or 'commited' in the database.

                              But if I declare something like this :
                               @In(create=true)
                               @Out(required=false)
                               @Valid
                               private Project project;
                              

                              a new row is 'persisted' or 'commited' in the database, by calling this method :
                              public String makePersistent() {
                               // Persist the data
                               hibernateSession.saveOrUpdate(project);
                               return "success";
                              }
                              

                              But I got an NullPointerException on the markForEdition() method.

                              If I declare like this :
                               @In(create=true)
                               @Out
                               private Project project;
                              

                              new row is inserted, but NOT the modified row.

                              If I just have this ( I removed the @out and @Valid ) :
                               @In(create=true)
                               private Project project;
                              

                              modified row did not get commited and no NPE error.

                              It looks for me that the problem is just around my @In and @Out.
                              Any idea ?

                              Thanks

                              • 12. Re: Using saveOrUpdate()
                                nusa

                                Anyone want to help me ?
                                Thanks.

                                • 13. Re: Using saveOrUpdate()
                                  gavin.king

                                  Submit a runnable zip of your project to JIRA, and I will take a quick look.

                                  • 14. Re: Using saveOrUpdate()
                                    nusa

                                     

                                    "gavin.king@jboss.com" wrote:
                                    Submit a runnable zip of your project to JIRA, and I will take a quick look.


                                    Thanks Gavin, but I'm using ADF in that project, and the war file is about
                                    5.5 MB ! I can send it without the adf jar files.
                                    Otherwise, the action class I'm using is this :
                                    package example.action;
                                    
                                    import static org.jboss.seam.annotations.Outcome.REDISPLAY;
                                    
                                    import java.util.List;
                                    import java.util.Iterator;
                                    
                                    import javax.faces.application.FacesMessage;
                                    import javax.faces.context.FacesContext;
                                    import javax.faces.event.ValueChangeEvent;
                                    
                                    import org.hibernate.criterion.Order;
                                    import org.hibernate.HibernateException;
                                    import org.hibernate.Session;
                                    import org.hibernate.validator.Valid;
                                    
                                    import org.jboss.logging.Logger;
                                    import org.jboss.seam.InterceptionType;
                                    import org.jboss.seam.annotations.IfInvalid;
                                    import org.jboss.seam.annotations.In;
                                    import org.jboss.seam.annotations.Intercept;
                                    import org.jboss.seam.annotations.Name;
                                    import org.jboss.seam.annotations.Out;
                                    import org.jboss.seam.contexts.Contexts;
                                    
                                    import oracle.adf.view.faces.component.core.data.CoreTable;
                                    
                                    import example.exceptions.SeamFacesException;
                                    import example.model.*;
                                    import example.util.*;
                                    
                                    @Intercept(InterceptionType.ALWAYS)
                                    @LoggedIn
                                    @Name("projectAction")
                                    public class ProjectAction {
                                    
                                     private static Logger log = Logger.getLogger(ProjectAction.class);
                                    
                                     //@Out(value="prj")
                                     @In(create=true)
                                     private Project project;
                                    
                                     private List<Project> listProject;
                                    
                                     @In
                                     private FacesContext facesContext;
                                    
                                     @In(create=true)
                                     private Session hibernateSession;
                                    
                                     private FacesMessage msg;
                                    
                                     public ProjectAction() {
                                     log.info("=== Constructor ...");
                                     }
                                    
                                     public List<Project> getFindAll() {
                                     log.info("=== getFindAll ... ");
                                     if (listProject == null)
                                     buildListProject();
                                     return listProject;
                                     }
                                    
                                     public void setFindAll(List<Project> prj) {
                                     this.listProject = prj;
                                     }
                                    
                                     @SuppressWarnings("unchecked")
                                     public void buildListProject() {
                                     log.info("=== buildListProject ... ");
                                     List<Project> list = null;
                                     try {
                                     list = hibernateSession.createCriteria(Project.class)
                                     .addOrder(Order.asc("projectName"))
                                     .list();
                                     log.info("=== buildListProject has : " + list.size());
                                     } catch (HibernateException ex) {
                                     throw new SeamFacesException("HibernateException raised : " + ex.toString());
                                     }
                                     setFindAll(list);
                                     }
                                    
                                     public String makePersistent() {
                                     log.info("=== makePersistent : " + project.toString());
                                    
                                     // Persist the data
                                     hibernateSession.saveOrUpdate(project);
                                    
                                     return "success";
                                     }
                                    
                                     @IfInvalid(outcome=REDISPLAY)
                                     public String markForEdition() {
                                     log.info("=== markForEdition ...");
                                    
                                     log.info("=== get dataAction ...");
                                     DataAction data = (DataAction)Contexts.getEventContext().get("dataAction");
                                    
                                     log.info("=== The obj is " + data.getClass().getName());
                                     CoreTable table = data.getTable();
                                    
                                     if ( table.isRowAvailable() ) {
                                     Project prj = (Project) table.getRowData();
                                     log.info("=== Attempting to update a row : " + prj.toString());
                                    
                                     prj = (Project)hibernateSession.merge(prj);
                                     //hibernateSession.update(project);
                                     //hibernateSession.saveOrUpdate(prj);
                                     return "success";
                                     } else {
                                     log.info("=== Couldn't find row !!!");
                                     msg = MessageFactory.getMessage(facesContext ,"NoUpdate");
                                     facesContext.addMessage(null, msg);
                                     }
                                    
                                     return null;
                                     }
                                    
                                    }
                                    


                                    Appreciate your help.

                                    1 2 Previous Next