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.  [ 3 posts ] 
Author Message
 Post subject: Validating uniqueness of an object
PostPosted: Fri Jul 14, 2006 1:53 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hi,

I am implementing some logic in my domain that ensures that one of my objects has a unique value in one of its properties, e.g. Customer.SocialSecurityNumber.

During the update of a Customer object, I trigger various pieces of validation logic, however, when I execute an NH query of the DB to make sure that there are no other customers in the DB with the same SocialSecurityNumber, I get an exception due to a unique constraint in the DB.

I figured out that this was due to the default auto flush behaviour in NH and I can change this by setting the FlushMode on the session to Commit instead of Auto. However, I am not sure of the implications of doing this and am wondering if I should only set it for this one query and then flip it back to Auto after the query executes.

Any guidance appreciated.

Thanks,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 7:39 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, it's ok to disable flushing just for one query.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 1:56 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Thanks Sergey. I assume that it would be bad practice to change the FlushMode to Commit globally then and should just do it on an as-needed basis.


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