I cannot let spring+hibernate commit a transaction.
It is a very simple single insert and commit. A very simple test table. No foreign key.
When I look at the MySQL server query log, it is natural for me to assume that the correct sql statements are issued, including a 'commit' statement.
Yet no record is actually inserted!
I did search the reference manuals, the forums and the net but still no hint. I already disabled autocommit for the database. Conversely if I allowed autocommit in the database, no rollback is successful :(
Did I miss anything?
Thank you very much!
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: Hibernate 3.2.5
Mapping documents:
<class name="mytransaction.Product" table="product">
<id name="id"><generator class="native"/></id>
<property name="name"/>
</class>
Code between sessionFactory.openSession() and session.close():
class MyHibernateCallback implements HibernateCallback {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Product product;
product = new Product();
product.setName("New product");
session.save(product);
session.flush();
return true;
}
}
Full stack trace of any exception that occurs: No exception, but no record is actually inserted even though it seems to me that a insert and a commit statement have been generated.
Name and version of the database you are using:
MySQLServer 5.1.23-rc-community-log
The generated SQL (show_sql=true):
/* insert mytransaction.Product */ insert into product (name) values ('New product')
Debug level Hibernate log excerpt:
Apr 24, 2008 11:12:18 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@1e4457d: display name [org.springframework.context.support.FileSystemXmlApplicationContext@1e4457d]; startup date [Thu Apr 24 11:12:18 CST 2008]; root of context hierarchy
Apr 24, 2008 11:12:19 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [E:\20070918\easymove\nb60f\wstest1\web\WEB-INF\db-config_hibernate.xml]
Apr 24, 2008 11:12:19 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [E:\20070918\easymove\nb60f\wstest1\src\java\mytransaction\transaction-config.xml]
Apr 24, 2008 11:12:19 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext@1e4457d]: org.springframework.beans.factory.support.DefaultListableBeanFactory@e45076
Apr 24, 2008 11:12:19 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@e45076: defining beans [dataSource0,dataSourceTarget,pool,dsConnectionFactory,poolableConnectionFactory,dataSource,lobHandler,sessionFactory,loginDao,testCaseDao,discussionDao,histPaginatorFactory,histPaginator,myUserDao,myUserProductServiceDefault,myUserProductService,txManager]; root of factory hierarchy
Apr 24, 2008 11:12:19 AM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: login.MyUser -> user
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: login.Lang -> lang
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: discussion.SayTopic -> saytopic
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: discussion.SayBox -> saybox
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: testcase.TestCaseCat -> testcasecat
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: testcase.TestCase -> testcase
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: mytransaction.Product -> product
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: discussion.SayTopic.sayBoxes -> saybox
Apr 24, 2008 11:12:20 AM org.hibernate.cfg.HbmBinder bindCollectionSecondPass
INFO: Mapping collection: testcase.TestCaseCat.testCases -> testcase
Apr 24, 2008 11:12:20 AM org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory
INFO: Building new Hibernate SessionFactory
Apr 24, 2008 11:12:20 AM org.hibernate.connection.ConnectionProviderFactory newConnectionProvider
INFO: Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.1.23-rc-community-log
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.0.8 ( Revision: ${svn.Revision} )
Apr 24, 2008 11:12:21 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Apr 24, 2008 11:12:21 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Apr 24, 2008 11:12:21 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: on_close
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: enabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Apr 24, 2008 11:12:21 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Hibernate: /* insert mytransaction.Product */ insert into product (name) values (?)
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Apr 24, 2008 11:12:21 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Apr 24, 2008 11:12:21 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Apr 24, 2008 11:12:21 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 4.234 sec
------------- Standard Output ---------------
Hibernate: /* insert mytransaction.Product */ insert into product (name) values (?)
------------- ---------------- ---------------
Hibernate configuration in Spring:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
destroy-method="destroy">
<property name="dataSource"><ref bean="dataSource"/> </property>
<property name="mappingResources">
<list>
<value>login/MyUser.hbm.xml</value>
<value>discussion/SayTopic.hbm.xml</value>
<value>testcase/TestCase.hbm.xml</value>
<value>mytransaction/Product.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- <prop key="hibernate.format_sql">true</prop>-->
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.connection.autocommit">false</prop>
</props>
</property>
</bean>
----------------------------
Problems with Session and transaction handling?
Yes, the transaction cannot commit
Read this:
http://hibernate.org/42.html
----------------------------