• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Hibernate Transactions

 
Mohana Priya
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I am using Hibernate Session injected in my EJB3 Session Bean code for my database operations.
@PersistenceContext
private Session session;

I am trying to put the below operations inside a transaction block.



If any one of the inserts fail ,say If insert of Child Table 2 fails
,I want the insert of the Parent Table alone to be rolled back .How would I achieve this in my code ?
Hope my query is clear.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I want the insert of the Parent Table alone to be rolled back .How would I achieve this in my code ?

So, you don't want to rollback either successful child insert?
 
Mohana Priya
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If insert of Child Table 2 fails ,Insert of Parent Table 1 and Parent Table 2 should be rolled back.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. It looks like the pseudo code you have posted will do just that, unless I'm missing something?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic