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: Transactions with Spring and Hibernate
PostPosted: Mon May 08, 2006 5:08 pm 
Newbie

Joined: Thu May 04, 2006 11:34 pm
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Hi,
I have 2 tables with one-to-many association.When I do an insert into the one table I get the ID of it and do an insert into the many table that Id and other values for the many table.
If I get an exception while inserting in the many table the one table is not getting rolled back.I need to put this unit of work in a transaction.

My question is how do i do this in a transaction.I know with hibernate you have begin and end transaction.I am using spring with hibernate and calling hibernate methods using getHibernateTemplate() method.

Can anyone help me ??


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 8:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I dont use spring but see their manual
http://static.springframework.org/spring/docs/1.2.x/reference/orm.html#orm-hibernate

You could test using a typical transaction using just hibernate's API with the following code outline:
Code:
Session sess = factory.openSession();
Transaction tx;
try {
     tx = sess.beginTransaction();
     //do some work
     ...
     tx.commit();
}
catch (Exception e) {
     if (tx!=null) tx.rollback();
     throw e;
}
finally {
     sess.close();
}



You should read hibernates manual on parent and child relationships.

http://www.hibernate.org/hib_docs/v3/reference/en/html/example-parentchild.html


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.