-->
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.  [ 5 posts ] 
Author Message
 Post subject: why not in transaction?
PostPosted: Mon Mar 05, 2012 3:43 am 
Newbie

Joined: Mon Mar 05, 2012 3:31 am
Posts: 2
hi,i'm new in hibernate and spring,this is my config,but its not in a transaction,it seems has no transaction,
applicationContext.xml file:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name="configLocation" value="classpath:jbpm.hibernate.cfg.xml" />
<property name="dataSource" ref="dataSource" />
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut expression="execution(* com.test.TransAction.*(..))" id="txPointcut"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >

<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@172.17.1.1:1521:database" />
<property name="username" value="test" />
<property name="password" value="test" />
</bean>

<bean id="transAction" class="com.test.TransAction">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
hibernate file:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.format_sql">false</property>
<property name="hibernate.jdbc.batch_size">0</property>

</session-factory>
</hibernate-configuration>


test class:
public class TransAction extends HibernateDaoSupport {
private SessionFactory sessionFactory;


public void testTrans3() throws RuntimeException{
Session session=this.getSession();


SQLQuery query1=session.createSQLQuery("update deployment set timestamp_='20120219'");
query1.executeUpdate();

SQLQuery query=session.createSQLQuery("update deployment set timestamp_='20120301089089058795789'");
query.executeUpdate();

}
}
when it runs,the first sql is updated,and the second sql throws exception,but first sql cannt rollback,what's wrong with my config,can anyone help me? thanks a lot


Top
 Profile  
 
 Post subject: Re: why not in transaction?
PostPosted: Mon Mar 05, 2012 3:53 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
You probably missed to open a transaction explicitly by calling

Code:
session.getTransaction().begin();


so all your updates were executed with autocommit (=single implicit transaction per jdbc-statement).


Top
 Profile  
 
 Post subject: Re: why not in transaction?
PostPosted: Mon Mar 05, 2012 4:02 am 
Newbie

Joined: Mon Mar 05, 2012 3:31 am
Posts: 2
pb00067 wrote:
You probably missed to open a transaction explicitly by calling

Code:
session.getTransaction().begin();


so all your updates were executed with autocommit (=single implicit transaction per jdbc-statement).


i want to let it works by auto transaction,i configed in application config file with
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut expression="execution(* com.test.TransAction.*(..))" id="txPointcut"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>

but it not works


Top
 Profile  
 
 Post subject: Re: why not in transaction?
PostPosted: Tue Mar 06, 2012 8:37 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
i want to let it works by auto transaction


What do you mean with 'auto transaction'?

I suggest you to read the hibernate documentation, chapter "Database transaction demarcation"


Top
 Profile  
 
 Post subject: Re: why not in transaction?
PostPosted: Tue Jun 12, 2012 8:38 am 
Newbie

Joined: Tue Jun 12, 2012 8:35 am
Posts: 1
Location: 3161 Ala Ilima St, Honolulu, HI 96818
What codes do you want? Can you specify on what are you working?

_________________
invitaciones bautizo


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.