6 Replies Latest reply on Sep 28, 2010 11:05 AM by lvdberg

    Intercept and change entity manager factory

    meneghette.meneghette.gmail.com

      Hi, I'm making an application that will connect with 2 different database Oracle and Postgre, and I want, when the hibernate will create a entity manager, configure the specific dialect and others thing,


      I want to know, how to intercept and override on seam, to do this.

        • 1. Re: Intercept and change entity manager factory
          lvdberg

          Hi,


          This is basic JPA or Hibernat stuff, so the best thing you can do is get the info from the Hibernat forum. At the momentyou have the persistency working its just a matter of configuring the two configurations in compomnents.xml and you can use them in your Seam application.


          Leo

          • 2. Re: Intercept and change entity manager factory
            meneghette.meneghette.gmail.com

            Hello Leo,


            Thanks for your reply, I will try on hibernate Forum,


            I will use tow configuration on components, but I need for example change the property showsql, dynamic, so I really need to intercept where seam create the entity manager, and change the properties.


            I search and I did not find how to do this.


            If someone had the same problem, please, help.

            • 3. Re: Intercept and change entity manager factory
              lvdberg

              Hi,


              You can configure Hibernate in components.xml, but I doubt if you're able to change the logging dynamically. I know it can be done with JBoss-tools, bt this is NOT dynamic.


              Leo

              • 4. Re: Intercept and change entity manager factory
                meneghette.meneghette.gmail.com

                Hi,


                Can you give just one example, how to configure Hibernate in components.xml ?


                Tks

                • 5. Re: Intercept and change entity manager factory
                  meneghette.meneghette.gmail.com

                  Founded a solution




                  <persistence:entity-manager-factory     name="siqWebEntityManagerFactory" persistence-unit-name="siqweb" >
                            <persistence:persistence-unit-properties >
                                 <key>hibernate.dialect</key>
                                 <value>#{siqDatabaseConnection.dialect}</value>
                                 
                                 <key>hibernate.show_sql</key>
                                 <value>#{siqDatabaseConnection.show_sql}</value>          
                                 
                                 <key>hibernate.format_sql</key>
                                 <value>#{siqDatabaseConnection.format_sql}</value>     
                                 
                                 <key>hibernate.hbm2ddl.auto</key>
                                 <value>#{siqDatabaseConnection.hbm2ddl}</value>
                                 
                                 <key>hibernate.transaction.manager_lookup_class</key>
                                 <value>#{siqDatabaseConnection.manager_lookup_class}</value>
                                 
                                 <key>hibernate.search.default.directory_provider</key>
                                 <value>#{siqDatabaseConnection.directory_provider}</value>
                                 
                                 <key>hibernate.search.default.indexBase</key>
                                 <value>#{siqDatabaseConnection.indexBase}</value>
                            </persistence:persistence-unit-properties>
                       </persistence:entity-manager-factory>



                  And The component




                  import org.jboss.seam.annotations.AutoCreate;
                  import org.jboss.seam.annotations.Name;
                  
                  @Name("siqDatabaseConnection")
                  @AutoCreate
                  public class SiqDatabaseConnection {
                  
                       //Values True or False
                      private String show_sql = "false";
                      
                      //Any Directory
                      private String indexBase = "c:/lucene/index/";
                      
                      //Always Update
                      private String hbm2ddl = "update";
                      
                      //Values True or False
                      private String format_sql = "false";
                      
                      //JBOSS=org.hibernate.transaction.JBossTransactionManagerLookup
                      private String manager_lookup_class = "org.hibernate.transaction.JBossTransactionManagerLookup";
                      
                      //DIRECTORY=org.hibernate.search.store.FSDirectoryProvider
                      private String directory_provider = "org.hibernate.search.store.FSDirectoryProvider";
                      
                      //ORACLE = org.hibernate.dialect.Oracle9Dialect
                      //POSTGRE = org.hibernate.dialect.PostgreSQLDialect
                      private String dialect = "org.hibernate.dialect.PostgreSQLDialect";
                      
                      public SiqDatabaseConnection(){
                             here you can read from a file for examplo
                      }
                  
                       
                  
                       public String getShow_sql() {
                            return show_sql;
                       }
                  
                  
                  
                       public void setShow_sql(String show_sql) {
                            this.show_sql = show_sql;
                       }
                  
                  
                  
                       public String getIndexBase() {
                            return indexBase;
                       }
                  
                       public void setIndexBase(String indexBase) {
                            this.indexBase = indexBase;
                       }
                  
                       public String getHbm2ddl() {
                            return hbm2ddl;
                       }
                  
                       public void setHbm2ddl(String hbm2ddl) {
                            this.hbm2ddl = hbm2ddl;
                       }
                  
                       public String getFormat_sql() {
                            return format_sql;
                       }
                  
                       public void setFormat_sql(String format_sql) {
                            this.format_sql = format_sql;
                       }
                  
                       public String getManager_lookup_class() {
                            return manager_lookup_class;
                       }
                  
                       public void setManager_lookup_class(String manager_lookup_class) {
                            this.manager_lookup_class = manager_lookup_class;
                       }
                  
                       public String getDirectory_provider() {
                            return directory_provider;
                       }
                  
                       public void setDirectory_provider(String directory_provider) {
                            this.directory_provider = directory_provider;
                       }
                  
                       public String getDialect() {
                            return dialect;
                       }
                  
                       public void setDialect(String dialect) {
                            this.dialect = dialect;
                       }
                  }
                  





                  • 6. Re: Intercept and change entity manager factory
                    lvdberg

                    Hi,


                    Looks good, thanks for sharing your solution.
                    Seam El is really everywhere....


                    Leo