We are trying to insert hibernate object and then select the same object with joins with other tables.
The insert is using hibernate
getHibernateTemplate().saveOrUpdate(onbrdStfRqmtLoadObj)
The select is in another function which is hibernate callback method and the select query is implimented in JDBC
When we are trying to run both functions in one transaction. Somehow the JDBC select is getting fired before the insert.
We are using BTM transaction Manager.
Attached is the spring
Code:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="btmConfig" factory-method="getConfiguration"
class="bitronix.tm.TransactionManagerServices">
<property name="serverId" value="spring-btm" />
</bean>
<!--create BTM transaction manager -->
<bean id="BitronixTransactionManager" factory-method="getTransactionManager"
class="bitronix.tm.TransactionManagerServices" depends-on="btmConfig,xaDataSource"
destroy-method="shutdown" />
<!-- Spring JtaTransactionManager-->
<bean id="jtaTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="BitronixTransactionManager" />
<property name="userTransaction" ref="BitronixTransactionManager" />
</bean>
<bean id="transactionController" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="jtaTransactionManager" />
<property name="transactionAttributes">
<props>
<prop key="handle*">PROPAGATION_REQUIRED, -Exception</prop>
<prop key="get*">PROPAGATION_REQUIRED, -Exception</prop>
<prop key="upd*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="create*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="do*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="remove*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly,-Exception</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly,-Exception</prop>
</props>
</property>
<property name="target" ref="transactionControllerTarget" />
</bean>
<bean id="transactionControllerTarget" class="com.ual.ods.test.crew.TransactionController">
<property name="dao">
<ref bean="LoadStaffingGuidelinesDao"/>
</property>
</bean>
<bean id="xaDataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource"
init-method="init" destroy-method="close">
<property name="className" value="oracle.jdbc.xa.client.OracleXADataSource" />
<property name="uniqueName" value="oracle" />
<property name="minPoolSize" value="2" />
<property name="maxPoolSize" value="16" />
<property name="acquireIncrement" value="2" />
<property name="allowLocalTransactions" value="true" />
<property name="testQuery" value="SELECT 1 FROM DUAL" />
<property name="useTmJoin" value="true" />
<property name="deferConnectionRelease" value="true" />
<property name="automaticEnlistingEnabled" value="true" />
<property name="acquisitionTimeout" value="1" /> <!-- need to check value -->
<property name="acquisitionInterval" value="1" />
<property name="preparedStatementCacheSize" value="5" />
<property name="driverProperties">
<props>
<prop key="user">ual_ods_dev01</prop>
<prop key="password">1forods</prop>
<prop key="URL">jdbc:oracle:thin:@161.215.22.16:1531:ods1</prop>
</props>
</property>
</bean>
<!-- Hibernate -->
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="xaDataSource" />
<property name="configLocation"
value="classpath:crew.hibernate.cfg.xml">
</property>
</bean>
<bean id="LoadStaffingGuidelinesDao" class="com.ual.ods.crew.dal.hibernateImpl.LoadStaffingGuidelinesHibernateImpl">
<property name="sessionFactory">
<ref bean="hibernateSessionFactory" />
</property>
</bean>
</beans>
Here is the JDBC Callback method:
Code:
final Vector<LoadStaffingGuidelinesDto> retVec = new Vector<LoadStaffingGuidelinesDto>();
System.out.println("$$$$13" + getHibernateTemplate().getSessionFactory().getCurrentSession().getTransaction().toString());
try {
return (List<LoadStaffingGuidelinesDto>) getHibernateTemplate().execute(new HibernateCallback(){
@Override
public Object doInHibernate(Session session) throws HibernateException, SQLException {
System.out.println("$$$"+session.getTransaction().toString());
SQLQuery query = session.createSQLQuery( getLoadStaffGuidelinesSql())
.addScalar("CARR_IATA_CD", Hibernate.STRING).addScalar("FLT_NBR", Hibernate.STRING)
........
......
.......
...