-->
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.  [ 1 post ] 
Author Message
 Post subject: Newbie Q:any issue nesting jdbc and hibernate transactions
PostPosted: Sat Aug 29, 2009 2:15 pm 
Newbie

Joined: Sat Aug 29, 2009 1:15 pm
Posts: 1
I want to use a outer hibernate transaction and an inner jdbc transaction as below.
I am new to Hibernate and i want to know, will nesting of transactions pose any issue even if it works.

Transaction transaction = session.beginTransaction();
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession(new LoggerInterceptor());
Transaction transaction = null;
Connection con =null;

try{
transaction = session.beginTransaction();
session.save(obj1);
session.save(obj2);
//
Session session1 = sessionFactory.openSession();
con = session1.getConnection();
//Needed to start a new transaction to be used in legacy code
con.setAutoCommit(false);
//Do db operations

if(transaction.isActive()){
con.commit();
transaction.commit();

}
}catch(Exception e1){
session.clear();
transaction.rollback();
}
//clean -up code
.....

Thanks in advance,
Naveen


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

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.