hm,.. the thing is when I use the hbm.xml file the insertion actually does not occur - which would be the situation I'd like to have (i.e. if some exception occurs and spring tells the transaction to roll-back I really would like to have the database state as before starting the transaction). but on the other side, using hibernate annotations (keeping the transaction configuration identical) always persists the entity - no matter if a roll-back occurs or not.
What would be the strategy to guarantee that a roll-back really sets back the original db state?
thanks
john
debug output using hibernate annotations
Code:
2006-04-17 16:50:08,917 DEBUG [org.hibernate.impl.SessionImpl] - <opened session at timestamp: 4691089034665984>
2006-04-17 16:50:08,955 DEBUG [org.hibernate.transaction.JDBCTransaction] - <begin>
2006-04-17 16:50:08,955 DEBUG [org.hibernate.jdbc.ConnectionManager] - <opening JDBC connection>
2006-04-17 16:50:08,956 DEBUG [org.hibernate.transaction.JDBCTransaction] - <current autocommit status: true>
2006-04-17 16:50:08,957 DEBUG [org.hibernate.transaction.JDBCTransaction] - <disabling autocommit>
2006-04-17 16:50:08,957 DEBUG [org.hibernate.jdbc.JDBCContext] - <after transaction begin>
2006-04-17 16:50:08,962 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - <Bound value [org.springframework.jdbc.datasource.ConnectionHolder@aa3e5b] for key [org.apache.commons.dbcp.BasicDataSource@39452f] to thread [main]>
2006-04-17 16:50:08,962 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - <Bound value [org.springframework.orm.hibernate3.SessionHolder@b57af1] for key [org.hibernate.impl.SessionFactoryImpl@9a99eb] to thread [main]>
2006-04-17 16:50:08,963 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - <Initializing transaction synchronization>
2006-04-17 16:50:08,964 INFO [ApplicationTest] - <Began transaction (1): transaction manager [org.springframework.orm.hibernate3.HibernateTransactionManager@1ef45e0]; default rollback = true>
2006-04-17 16:50:08,988 DEBUG [org.springframework.transaction.interceptor.TransactionInterceptor] - <Getting transaction for org.transaction.UserBean.createUser>
2006-04-17 16:50:08,988 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate3.SessionHolder@b57af1] for key [org.hibernate.impl.SessionFactoryImpl@9a99eb] bound to thread [main]>
2006-04-17 16:50:08,988 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - <Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@aa3e5b] for key [org.apache.commons.dbcp.BasicDataSource@39452f] bound to thread [main]>
2006-04-17 16:50:09,017 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]>
2006-04-17 16:50:09,089 INFO [org.springframework.jdbc.support.SQLErrorCodesFactory] - <SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]>
2006-04-17 16:50:09,098 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - <Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@aa3e5b] for key [org.apache.commons.dbcp.BasicDataSource@39452f] bound to thread [main]>
2006-04-17 16:50:09,100 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - <Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@aa3e5b] for key [org.apache.commons.dbcp.BasicDataSource@39452f] bound to thread [main]>
2006-04-17 16:50:09,100 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate3.SessionHolder@b57af1] for key [org.hibernate.impl.SessionFactoryImpl@9a99eb] bound to thread [main]>
2006-04-17 16:50:09,100 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate3.SessionHolder@b57af1] for key [org.hibernate.impl.SessionFactoryImpl@9a99eb] bound to thread [main]>
2006-04-17 16:50:09,105 DEBUG [org.hibernate.event.def.DefaultSaveOrUpdateEventListener] - <saving transient instance>
2006-04-17 16:50:09,108 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - <saving [org.transaction.User#<null>]>
2006-04-17 16:50:09,108 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - <executing insertions>
2006-04-17 16:50:09,134 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] - <executing identity-insert immediately>
2006-04-17 16:50:09,134 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] - <Inserting entity: org.transaction.User (native id)>
2006-04-17 16:50:09,136 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <about to open PreparedStatement (open PreparedStatements: 0, globally: 0)>
2006-04-17 16:50:09,136 DEBUG [org.hibernate.SQL] - <insert into User (password, userName) values (?, ?)>
Hibernate: insert into User (password, userName) values (?, ?)
2006-04-17 16:50:09,136 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <preparing statement>
2006-04-17 16:50:09,167 DEBUG [org.hibernate.persister.entity.AbstractEntityPersister] - <Dehydrating entity: [org.transaction.User#<null>]>
2006-04-17 16:50:09,167 DEBUG [org.hibernate.type.StringType] - <binding 'pw' to parameter: 1>
2006-04-17 16:50:09,169 DEBUG [org.hibernate.type.StringType] - <binding 'userName' to parameter: 2>
2006-04-17 16:50:09,171 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] - <Natively generated identity: 26>
2006-04-17 16:50:09,171 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <about to close PreparedStatement (open PreparedStatements: 1, globally: 1)>
2006-04-17 16:50:09,171 DEBUG [org.hibernate.jdbc.AbstractBatcher] - <closing statement>
2006-04-17 16:50:09,178 DEBUG [org.springframework.transaction.interceptor.RuleBasedTransactionAttribute] - <Applying rules to determine whether transaction should rollback on java.lang.RuntimeException>
2006-04-17 16:50:09,178 DEBUG [org.springframework.transaction.interceptor.RuleBasedTransactionAttribute] - <Winning rollback rule is: null>
2006-04-17 16:50:09,178 DEBUG [org.springframework.transaction.interceptor.RuleBasedTransactionAttribute] - <No relevant rollback rule found: applying superclass default>
2006-04-17 16:50:09,178 DEBUG [org.springframework.transaction.interceptor.TransactionInterceptor] - <Invoking rollback for transaction on org.transaction.UserBean.createUser due to throwable [java.lang.RuntimeException]>
2006-04-17 16:50:09,179 DEBUG [org.hibernate.transaction.JDBCTransaction] - <rollback>
2006-04-17 16:50:09,204 DEBUG [org.hibernate.transaction.JDBCTransaction] - <re-enabling autocommit>
2006-04-17 16:50:09,205 DEBUG [org.hibernate.transaction.JDBCTransaction] - <rolled back JDBC Connection>
2006-04-17 16:50:09,205 DEBUG [org.hibernate.jdbc.JDBCContext] - <after transaction completion>
2006-04-17 16:50:09,205 DEBUG [org.hibernate.jdbc.ConnectionManager] - <transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!>
2006-04-17 16:50:09,205 DEBUG [org.hibernate.impl.SessionImpl] - <after transaction completion>
2006-04-17 16:50:09,206 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - <Clearing transaction synchronization>
2006-04-17 16:50:09,206 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - <Removed value [org.springframework.orm.hibernate3.SessionHolder@b57af1] for key [org.hibernate.impl.SessionFactoryImpl@9a99eb] from thread [main]>
2006-04-17 16:50:09,206 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] - <Removed value [org.springframework.jdbc.datasource.ConnectionHolder@aa3e5b] for key [org.apache.commons.dbcp.BasicDataSource@39452f] from thread [main]>
2006-04-17 16:50:09,206 DEBUG [org.hibernate.impl.SessionImpl] - <closing session>
2006-04-17 16:50:09,207 DEBUG [org.hibernate.jdbc.ConnectionManager] - <performing cleanup>
2006-04-17 16:50:09,207 DEBUG [org.hibernate.jdbc.ConnectionManager] - <releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]>
2006-04-17 16:50:09,212 DEBUG [org.hibernate.jdbc.JDBCContext] - <after transaction completion>
2006-04-17 16:50:09,212 DEBUG [org.hibernate.jdbc.ConnectionManager] - <transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!>
2006-04-17 16:50:09,212 DEBUG [org.hibernate.impl.SessionImpl] - <after transaction completion>