-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: transaction issue in spring HibernateCallback
PostPosted: Fri Jan 30, 2009 7:54 pm 
Newbie

Joined: Thu Jan 15, 2009 3:55 pm
Posts: 12
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)
........
......
.......
...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 01, 2009 6:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
this is for hibernate related tools, you should ask your question in the main user forum or spring (especially since your questions is more about how spring works than how hibernate works)

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.