5 Replies Latest reply on Dec 19, 2007 5:12 PM by pmuir

    Problem with manual flush mode for managed persistence conte

    nickarls

      Hi, I have a problem trying to delay my inserts using manual flush mode.

      I have followed the manual as far as possible but hibernate still insists on inserting in the middle of the conversation (verified using conversation observers)

      I have

       <persistence:managed-persistence-context name="entityManager"
       auto-create="true"
       persistence-unit-jndi-name="java:/conceptEntityManagerFactory" />
      
      

      and
       @PersistenceContext(type=EXTENDED)
       private EntityManager entityManager;
      

      and
       @Begin(flushMode=MANUAL)
       public String start() {
       return "/concept.xhtml";
       }
      

      and
       public String insert() {
       FooEntity entity = new FooEntity();
       entity.setData("foo");
       entityManager.persist(entity);
       return "/concept.xhtml";
       }
      

      and
       @End
       public String flush() {
       entityManager.flush();
       return "/concept.xhtml";
       }
      

      and
      @Entity
      @Name("fooEntity")
      @Scope(SESSION)
      @Table(name="footable")
      public class FooEntity {
       private Integer id;
       private String data;
      
       @Id @GeneratedValue @Column(name="id_col")
       public Integer getId() {
       return id;
       }
      
       public void setId(Integer id) {
       this.id = id;
       }
      
       @Column(name="data_col") @NotNull @Length(min=5, max=15)
       public String getData() {
       return data;
       }
      
       public void setData(String data) {
       this.data = data;
       }
      }
      


      Have I misunderstood something or shouldn't I see the inserts happening when the conversation ends (clicking the bound start-insert-flush buttons in that order)?

        • 1. Re: Problem with manual flush mode for managed persistence c
          pmuir

          You need to use a SMPC

          • 2. Re: Problem with manual flush mode for managed persistence c
            nickarls

             

            "pete.muir@jboss.org" wrote:
            You need to use a SMPC


            Aah, indeed, thanks. Would I also be getting the SMPC by using the getEntityManager() in EntityHome and the standard PC by using the getPersistenceContext() in PersistenceController?

            • 3. Re: Problem with manual flush mode for managed persistence c
              pmuir

              No, both would return an SMPC (getPersistenceContext can also return a Seam managed hibernate session)

              • 4. Re: Problem with manual flush mode for managed persistence c
                asookazian

                Does SMPC work with multiple datasources in the same app? If yes how would you configure the @In injection attribute similar to the @PersistenceContext JPA attribute which you can specify a persistenceUnit name? In the API for the Seam @In annotation there is no element similar to unitName...

                 @PersistenceContext(unitName="boIcomsSecurityAudit", type=PersistenceContextType.EXTENDED)
                 private EntityManager em;
                
                 //@In(create=true)
                 //EntityManager em; //a Seam-managed persistence context

                I have xyz-ds.xml as below:

                <datasources>
                
                 <local-tx-datasource>
                 <jndi-name>boIcomsSecurityAuditDatasource</jndi-name>
                 <connection-url>jdbc:sqlserver://CORG0DV01:1433;databaseName=boIcomsSecurityAudit</connection-url>
                 <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
                 <user-name>_AppUser_JavaTestAcct</user-name>
                 <password>JavaTestAcct</password>
                 </local-tx-datasource>
                
                 <local-tx-datasource>
                 <jndi-name>coxDSSDatasource</jndi-name>
                 <connection-url>jdbc:sqlserver://CORG0DV01:1433;databaseName=coxDSS</connection-url>
                 <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
                 <user-name>_AppUser_JavaTestAcct</user-name>
                 <password>JavaTestAcct</password>
                 </local-tx-datasource>
                
                 <local-tx-datasource>
                 <jndi-name>coxIMDatasource</jndi-name>
                 <connection-url>jdbc:sqlserver://CORG0DV01:1433;databaseName=coxIM</connection-url>
                 <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
                 <user-name>_AppUser_JavaTestAcct</user-name>
                 <password>JavaTestAcct</password>
                 </local-tx-datasource>
                
                </datasources>


                • 5. Re: Problem with manual flush mode for managed persistence c
                  pmuir

                  You would set up multiple entity manager components in components.xml like

                  <persistence:managed-persistence-context name="entityManager1" persistence-unit-jndi-name="java:/EntityManagerFactory1" />
                  
                  <persistence:managed-persistence-context name="entityManager2" persistence-unit-jndi-name="java:/EntityManagerFactory2" />


                  @In EntityManager entityManager1;
                  @In EntityManager entityManager2;