I originally had no transactionManager specified, as we believed that EJB3 was managing transaction start, HibernateSession was using the tx aware datasource associated with the thread. We thought we only needed to configure JTA if using > 1 database etc.
Anyhow, I have just tried configuring JTA (we're using JBoss), but I get the same result - in that the IdTransferringMergeEventListener still gets id of null.
application context snipped :-
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransactionName"><null/></property>
<property name="transactionManagerName">
<value>java:/TransactionManager</value>
</property>
</bean>
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="mformDS" />
<property name="annotatedClasses" ref="annotatedClassesList">
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.query.factory_class">
org.hibernate.hql.classic.ClassicQueryTranslatorFactory
</prop>
<prop key="hibernate.show_sql">£{hibernate.show_sql}</prop>
</props>
</property>
<property name="eventListeners">
<map>
<entry>
<key>
<value>pre-update</value>
</key>
<ref bean="validatePreUpdateEventListener"/>
</entry>
<entry>
<key>
<value>pre-insert</value>
</key>
<ref bean="validatePreInsertEventListener"/>
</entry>
<entry key="merge">
<bean class="com.rdf.infra.spring.hibernate3.support.IdTransferringMergeEventListener"/>
</entry>
</map>
</property>
</bean>
EJB3 transaction annotations :-
import javax.ejb.TransactionAttribute;
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public SearchCriteriaDTO saveSearchCriteria(String userId, SearchCriteriaDTO searchCriteria) {
return getDelegateBean().saveSearchCriteria(userId, searchCriteria);
}
thanks for your time.
In the log I can see the JTA mgr :-
16:47:54,060 INFO [JtaTransactionManager] Using JTA UserTransaction: org.springframework.transaction.jta.UserTransactionAdapter@735a55
16:47:54,060 INFO [JtaTransactionManager] Using JTA TransactionManager: org.jboss.tm.TxManager@12faeca
16:47:54,278 INFO [Version] Hibernate Annotations 3.2.0.CR1
16:47:54,310 INFO [Environment] Hibernate 3.2 cr2
16:47:54,310 INFO [Environment] loaded properties from resource hibernate.properties: {hibernate.bytecode.use_reflection_optimizer=false}
but then get :-
16:48:14,763 DEBUG [AbstractSaveEventListener] delaying identity-insert due to no transaction in progress
16:48:24,716 DEBUG [AbstractFlushingEventListener] processing flush-time cascades
16:48:24,716 DEBUG [AbstractFlushingEventListener] dirty checking collections
16:48:24,716 DEBUG [AbstractFlushingEventListener] Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
16:48:24,716 DEBUG [AbstractFlushingEventListener] Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
16:48:24,716 DEBUG [Printer] listing entities:
16:48:24,731 DEBUG [Printer] com.rdf.mform.domain.user.ExistingMortgageDetailsDO{monthlyPayment=component[currency,amount]{amount=49900, currency=GBP}, propertyLocation=England, loanAmount=component[currency,amount]{amount=50000000, currency=GBP}, loanAmountInterestPart=component[currency,amount]{amount=0, currency=GBP}, repaymentType=Repayment, dealType=DiscountedVariable, latestVersion=0, id=null, loanAmountRepaymentPart=null, loanTermYears=10}
16:48:24,731 DEBUG [AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
16:48:24,731 DEBUG [ConnectionManager] opening JDBC connection
16:48:24,731 DEBUG [SQL] insert into existing_mortgage_details (latestVersion, repaymentType, loanAmountCur, loanAmount, loanTermYears, propertyLocation, loanAmountRepaymentPartCur, loanAmountRepaymentPart, loanAmountInterestPartCur, loanAmountInterestPart, dealType, monthlyPaymentCur, monthlyPayment) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
16:48:24,731 INFO [STDOUT] Hibernate: insert into existing_mortgage_details (latestVersion, repaymentType, loanAmountCur, loanAmount, loanTermYears, propertyLocation, loanAmountRepaymentPartCur, loanAmountRepaymentPart, loanAmountInterestPartCur, loanAmountInterestPart, dealType, monthlyPaymentCur, monthlyPayment) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
16:48:24,747 DEBUG [IdentifierGeneratorFactory] Natively generated identity: 1002
16:48:24,747 DEBUG [AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
16:48:24,747 DEBUG [ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
16:48:24,762 DEBUG [ConnectionManager] transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
|