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: Important questions I believe all newbies should start askin
PostPosted: Wed Aug 18, 2004 9:16 pm 
Beginner
Beginner

Joined: Sun Jun 20, 2004 11:39 pm
Posts: 24
Hello all,
I have a couple of conceptual questions that i need to find out from anyone one out there who might be able to answer me:

1) Is there anyway that i can find out if a session.save has failed due to a unique constraint so that i can catch the exception and know that the save has failed due to some value that is meant to be unique in the database but it isnt, and not becos of any other error like size too big for the column? basically how do i differentiate a specific error from a host of errors that can possibly happen in a session.save()?

2) i understand from a previous posting from Gavin King that it is not possible for hibernate to automatically save a newly created object with a t.commit() in a transaction, the new object has to be saved in a sess.save() call. i also do know from experience that in a parent-child relationship, the child will need to be saved first before the parent. ok now the problem is that in order to save a newly created parent object with its child objects, i would have to save each child object individually first before saving the parent object, but since i cant save all of them in a t.commit() in one fell swoop and rollback if there are any errors, what would be the best way to mitigate the damage caused should a sess.save() half way down a series of sess.save() fails and some objects have already been saved and cannot be rollbacked since calling t.rollback doesnt rollback sess.save()s?

Best Regards,
Steward


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 10:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
1) Well session.save() does not actually issue a SQL insert (the insert is done during flushing), so no. The jdbc exceptions are not typed to specific db errors (like say constraint violations vs system errors). Instead, applications are required to inspect the SQLException's SQLState and errorCode properties to make a determination of what actually went wrong in the database. Spring has a nice little SQLException parsing library.

2) I think you have serious misunderstandings about transactions... And you are incorrect about *having* to save children individually; you are just not understanding Hibernate's cascading capaibilities.


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.