1 Reply Latest reply on Jul 12, 2007 3:12 AM by ralscha

    Hibernate2 Problem

    ralscha

      Hello

      I found a strange behaviour with Hibernate2 Example in Seam 2.0.0B1.
      I deployed the example into Tomcat and it starts fine. In the browser I see the homepage with the login form.

      But everytime I start a request for example with "Register New User" or "Register" in the New User form the program prints the following log. It looks like everytime the program connects to the database it creates a new HibernateSessionFactory. So everytime it drops and creates the tables in the database because the SchemaExport tool is running.

      Regards
      Ralph

      16:13:56,093 INFO [Configuration] configuring from resource: /hibernate.cfg.xml
      
      16:13:56,109 INFO [Configuration] Configuration resource: /hibernate.cfg.xml
      16:13:56,109 INFO [Configuration] Configured SessionFactory: null
      16:13:56,109 INFO [AnnotationBinder] Binding entity from annotated class: org.j
      boss.seam.example.hibernate.Hotel
      16:13:56,109 INFO [EntityBinder] Bind entity org.jboss.seam.example.hibernate.H
      otel on table Hotel
      16:13:56,125 INFO [AnnotationBinder] Binding entity from annotated class: org.j
      boss.seam.example.hibernate.User
      16:13:56,125 INFO [EntityBinder] Bind entity org.jboss.seam.example.hibernate.U
      ser on table Customer
      16:13:56,125 INFO [AnnotationBinder] Binding entity from annotated class: org.j
      boss.seam.example.hibernate.Booking
      16:13:56,125 INFO [EntityBinder] Bind entity org.jboss.seam.example.hibernate.B
      ooking on table Booking
      16:13:56,140 INFO [NamingHelper] JNDI InitialContext properties:{}
      16:13:56,140 INFO [DatasourceConnectionProvider] Using datasource: java:comp/en
      v/jdbc/TestDB
      16:13:56,140 INFO [SettingsFactory] RDBMS: HSQL Database Engine, version: 1.7.2
      
      16:13:56,156 INFO [SettingsFactory] JDBC driver: HSQL Database Engine Driver, v
      ersion: 1.7.2
      16:13:56,156 INFO [Dialect] Using dialect: org.hibernate.dialect.HSQLDialect
      16:13:56,156 INFO [TransactionFactoryFactory] Transaction strategy: org.hiberna
      te.transaction.JDBCTransactionFactory
      16:13:56,156 INFO [TransactionManagerLookupFactory] No TransactionManagerLookup
       configured (in JTA environment, use of read-write or transactional second-level
       cache is not recommended)
      16:13:56,156 INFO [SettingsFactory] Automatic flush during beforeCompletion():
      enabled
      16:13:56,156 INFO [SettingsFactory] Automatic session close at end of transacti
      on: disabled
      16:13:56,156 INFO [SettingsFactory] JDBC batch size: 15
      16:13:56,171 INFO [SettingsFactory] JDBC batch updates for versioned data: disa
      bled
      16:13:56,171 INFO [SettingsFactory] Scrollable result sets: enabled
      16:13:56,171 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
      16:13:56,171 INFO [SettingsFactory] Connection release mode: auto
      16:13:56,171 INFO [SettingsFactory] Default batch fetch size: 1
      16:13:56,171 INFO [SettingsFactory] Generate SQL with comments: disabled
      16:13:56,171 INFO [SettingsFactory] Order SQL updates by primary key: disabled
      16:13:56,171 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.AST
      QueryTranslatorFactory
      16:13:56,171 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
      16:13:56,187 INFO [SettingsFactory] Query language substitutions: {}
      16:13:56,187 INFO [SettingsFactory] JPA-QL strict compliance: disabled
      16:13:56,187 INFO [SettingsFactory] Second-level cache: enabled
      16:13:56,187 INFO [SettingsFactory] Query cache: disabled
      16:13:56,187 INFO [SettingsFactory] Cache provider: org.hibernate.cache.Hashtab
      leCacheProvider
      16:13:56,187 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
      16:13:56,187 INFO [SettingsFactory] Structured second-level cache entries: disa
      bled
      16:13:56,187 INFO [SettingsFactory] Statistics: disabled
      16:13:56,187 INFO [SettingsFactory] Deleted entity synthetic identifier rollbac
      k: disabled
      16:13:56,187 INFO [SettingsFactory] Default entity-mode: pojo
      16:13:56,203 INFO [SessionFactoryImpl] building session factory
      16:13:56,218 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no
       JNDI name configured
      16:13:56,218 INFO [SchemaExport] Running hbm2ddl schema export
      16:13:56,234 INFO [SchemaExport] exporting generated schema to database
      16:13:56,234 INFO [SchemaExport] Executing import script: /import.sql
      16:13:56,234 INFO [SchemaExport] schema export complete
      


        • 1. Re: Hibernate2 Problem
          ralscha

          Think I figured out what the problem is:

          The class org.jboss.seam.persistence.HibernateSessionFactory has
          a "unwrap" method

          @Unwrap
           public SessionFactory getSessionFactory() throws Exception
           {
           return createSessionFactory();
           }


          and a "create" method
          @Create
           public void startup() throws Exception
           {
           sessionFactory = createSessionFactory();
           }


          and both call createSessionFactory. If I understand the wrap correctly the method will be called everytime the bean is referenced. This results in a new SessionFactory every time. I think the unwrap Method schould only return the sessionFactory.