Yes - I am not too sure if I actually need the outer transaction but I want the inner transaction to commit or rollback after each loop of saving data.
Here is my log output:
Code:
INFO Dialect - Using dialect: org.hibernate.dialect.DB2Dialect
INFO TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
INFO TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
INFO SettingsFactory - Automatic flush during beforeCompletion(): disabled
INFO SettingsFactory - Automatic session close at end of transaction: disabled
INFO SettingsFactory - Scrollable result sets: enabled
INFO SettingsFactory - JDBC3 getGeneratedKeys(): disabled
INFO SettingsFactory - Connection release mode: on_close
INFO SettingsFactory - Default schema: HAROLD_INGT
INFO SettingsFactory - Default batch fetch size: 1
INFO SettingsFactory - Generate SQL with comments: disabled
INFO SettingsFactory - Order SQL updates by primary key: disabled
INFO SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
INFO SettingsFactory - Query language substitutions: {}
INFO SettingsFactory - Second-level cache: enabled
INFO SettingsFactory - Query cache: disabled
INFO SettingsFactory - Cache provider: org.hibernate.cache.EhCacheProvider
INFO SettingsFactory - Optimize cache for minimal puts: disabled
INFO SettingsFactory - Structured second-level cache entries: disabled
INFO SettingsFactory - Statistics: disabled
INFO SettingsFactory - Deleted entity synthetic identifier rollback: disabled
INFO SettingsFactory - Default entity-mode: pojo
INFO SessionFactoryImpl - building session factory
INFO SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
DEBUG NameMatchTransactionAttributeSource - Adding transactional method[*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
DEBUG NameMatchTransactionAttributeSource - Adding transactional method [handleData] with attribute [PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,-za.co.sanlam.harold.support.agreement.astute.handler.exception.DataHandlerException,-Throwable]
DEBUG NameMatchTransactionAttributeSource - Adding transactional method[*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
DEBUG NameMatchTransactionAttributeSource - Adding transactional method[*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
DEBUG NameMatchTransactionAttributeSource - Adding transactional method[*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
DEBUG NameMatchTransactionAttributeSource - Adding transactional method[*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
DEBUG NameMatchTransactionAttributeSource - Adding transactional method[*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
DEBUG NameMatchTransactionAttributeSource - Adding transactional method[*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT]
DEBUG NameMatchTransactionAttributeSource - Adding transactional method[*] with attribute [PROPAGATION_REQUIRED,ISOLATION_DEFAULT,-za.co.sanlam.harold.integration.agreement.astute.exception.AstuteIntegrationException,-za.co.sanlam.harold.support.common.exception.HaroldSupportException]
............
Code:
DEBUG TransactionInterceptor - Completing transaction for [za.co.sanlam.harold.support.agreement.astute.handler.IAstuteDataHandler.handleData]
ERROR AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.TransientObjectException: za.co.sanlam.harold.model.payment.PaymentPart
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:216)
....
DEBUG TransactionSynchronizationManager - Removed value [org.springframework.orm.hibernate3.SessionHolder@f471e] for key [org.hibernate.impl.SessionFactoryImpl@18a9e64] from thread [main]
DEBUG TransactionSynchronizationManager - Clearing transaction synchronization
DEBUG TransactionSynchronizationManager - Removed value [org.springframework.orm.hibernate3.SessionHolder@1cec59b] for key [org.hibernate.impl.SessionFactoryImpl@1be496b] from thread [main]
DEBUG TransactionSynchronizationManager - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@121cbdb] for key [org.apache.commons.dbcp.BasicDataSource@a620f5] from thread [main]
DEBUG TransactionSynchronizationManager - Bound value [org.springframework.orm.hibernate3.SessionHolder@115272a] for key [org.hibernate.impl.SessionFactoryImpl@1be496b] to thread [main]
DEBUG TransactionSynchronizationManager - Bound value [org.springframework.jdbc.datasource.ConnectionHolder@15e10ab] for key [org.apache.commons.dbcp.BasicDataSource@a620f5] to thread [main]
DEBUG TransactionSynchronizationManager - Initializing transaction synchronization
DEBUG TransactionSynchronizationManager - Bound value [org.springframework.orm.hibernate3.SessionHolder@c8a027] for key [org.hibernate.impl.SessionFactoryImpl@18a9e64] to thread [main]
DEBUG TransactionInterceptor - Completing transaction for [za.co.sanlam.harold.integration.agreement.astute.callback.IAstuteCallback.saveData] after exception: org.springframework.dao.InvalidDataAccessApiUsageException: za.co.sanlam.harold.model.payment.PaymentPart; nested exception is org.hibernate.TransientObjectException: za.co.sanlam.harold.model.payment.PaymentPart
DEBUG RuleBasedTransactionAttribute - Applying rules to determine whether transaction should rollback on org.springframework.dao.InvalidDataAccessApiUsageException: za.co.sanlam.harold.model.payment.PaymentPart; nested exception is org.hibernate.TransientObjectException: za.co.sanlam.harold.model.payment.PaymentPart
DEBUG RuleBasedTransactionAttribute - Winning rollback rule is: null
DEBUG RuleBasedTransactionAttribute - No relevant rollback rule found: applying superclass default
DEBUG TransactionSynchronizationManager - Removed value [org.springframework.orm.hibernate3.SessionHolder@c8a027] for key [org.hibernate.impl.SessionFactoryImpl@18a9e64] from thread [main]
DEBUG TransactionSynchronizationManager - Clearing transaction synchronization
I can see that the outer bean's transaction is the one that is checking whether to commit or rollback.
(Ideally I would like the check on the inner transaction but I suppose the outer one is fine too as long as invalid data is not committed.)
It seems that if it applies the superclass default (which superclass?) then it should roll back for org.springframework.dao.InvalidDataAccessApiUsageE xception as it extends RuntimeException. But the data is committed to the database.
Thanks