-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA Hibernate Entity Manager and autocommit ?
PostPosted: Tue May 01, 2007 7:13 am 
Newbie

Joined: Fri Jan 23, 2004 4:02 am
Posts: 6
Location: Linz, Austria
I'm trying to use autocommit with a database accessed through Hibernate Entity Manager (JPA). After calling manager.persist() for a new object, this new object is not committed even though the driver has autocommit enabled.

The persistence unit is configured as shown below:
Code:
   <persistence-unit name="unit">

      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <mapping-file>META-INF/orm.xml</mapping-file>
      <class>contact.Contact</class>

      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
         <property name="hibernate.connection.url" value="jdbc:derby://localhost:1527/JavaDB;create=true" />
         <property name="hibernate.connection.username" value="user1" />
         <property name="hibernate.connection.password" value="user1" />

         <property name="hibernate.connection.autocommit" value="true" />
         <property name="hibernate.hbm2ddl.auto" value="create" />
         <property name="hibernate.show_sql" value="true" />
         <property name="hibernate.format_sql" value="true" />
         <property name="hibernate.transaction.factory_class"
            value="org.hibernate.transaction.JDBCTransactionFactory" />

      </properties>
   </persistence-unit>


The non JPA solution with the same hibernate settings does honor the autocommit setting. I can only get the JPA solution to work when I wrap the call to persist() in a begin and commit transaction call.

What configuration settings are required to utilize autocommit?

I'm using hibernate 3.2.1.ga with a derby 10.2.2.0 database

I get the log below when starting

Code:
13:04:46,621  INFO Version:15 - Hibernate EntityManager 3.2.1.GA
13:04:46,636  INFO Version:15 - Hibernate Annotations 3.2.1.GA
13:04:46,652  INFO Environment:500 - Hibernate 3.2.1
13:04:46,652  INFO Environment:533 - hibernate.properties not found
13:04:46,652  INFO Environment:667 - Bytecode provider name : cglib
13:04:46,652  INFO Environment:584 - using JDK 1.4 java.sql.Timestamp handling
13:04:46,886  WARN Ejb3Configuration:993 - Overriding hibernate.transaction.factory_class is dangerous, this might break the EJB3 specification implementation
13:04:47,042  INFO AnnotationBinder:388 - Binding entity from annotated class: contact.Contact
13:04:47,074  INFO EntityBinder:378 - Bind entity contact.Contact on table Contact
13:04:47,199  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
13:04:47,199  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
13:04:47,199  INFO DriverManagerConnectionProvider:45 - autocommit mode: true
13:04:47,199  WARN DriverManagerConnectionProvider:52 - no JDBC Driver class was specified by property hibernate.connection.driver_class
13:04:47,199  INFO DriverManagerConnectionProvider:80 - using driver: null at URL: jdbc:derby://localhost:1527/JavaDB;create=true
13:04:47,199  INFO DriverManagerConnectionProvider:86 - connection properties: {user=user1, password=****, autocommit=true, release_mode=auto}
13:04:47,402  INFO SettingsFactory:81 - RDBMS: Apache Derby, version: 10.2.2.0 - (485682)
13:04:47,402  INFO SettingsFactory:82 - JDBC driver: Apache Derby Network Client JDBC Driver, version: 10.2.2.0 - (485682)
13:04:47,480  INFO Dialect:151 - Using dialect: org.hibernate.dialect.DerbyDialect
13:04:47,496  INFO TransactionFactoryFactory:34 - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
13:04:47,496  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
13:04:47,496  INFO SettingsFactory:134 - Automatic flush during beforeCompletion(): disabled
13:04:47,496  INFO SettingsFactory:138 - Automatic session close at end of transaction: disabled
13:04:47,496  INFO SettingsFactory:153 - Scrollable result sets: enabled
13:04:47,496  INFO SettingsFactory:161 - JDBC3 getGeneratedKeys(): disabled
13:04:47,496  INFO SettingsFactory:169 - Connection release mode: auto
13:04:47,496  INFO SettingsFactory:196 - Default batch fetch size: 1
13:04:47,496  INFO SettingsFactory:200 - Generate SQL with comments: disabled
13:04:47,496  INFO SettingsFactory:204 - Order SQL updates by primary key: disabled
13:04:47,496  INFO SettingsFactory:369 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
13:04:47,496  INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
13:04:47,496  INFO SettingsFactory:212 - Query language substitutions: {}
13:04:47,496  INFO SettingsFactory:217 - JPA-QL strict compliance: enabled
13:04:47,496  INFO SettingsFactory:222 - Second-level cache: enabled
13:04:47,496  INFO SettingsFactory:226 - Query cache: disabled
13:04:47,496  INFO SettingsFactory:356 - Cache provider: org.hibernate.cache.NoCacheProvider
13:04:47,496  INFO SettingsFactory:241 - Optimize cache for minimal puts: disabled
13:04:47,496  INFO SettingsFactory:250 - Structured second-level cache entries: disabled
13:04:47,511  INFO SettingsFactory:270 - Echoing all SQL to stdout
13:04:47,511  INFO SettingsFactory:277 - Statistics: disabled
13:04:47,511  INFO SettingsFactory:281 - Deleted entity synthetic identifier rollback: disabled
13:04:47,511  INFO SettingsFactory:296 - Default entity-mode: pojo
13:04:47,527  INFO SessionFactoryImpl:161 - building session factory
13:04:47,746  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
13:04:47,933 DEBUG SQL:393 -


Thanks
Martin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.