-->
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: Validatable
PostPosted: Tue Mar 16, 2004 8:25 am 
Newbie

Joined: Tue Mar 16, 2004 7:14 am
Posts: 3
Location: Aachen, Germany
Hi there,

in the docs is stated that one cannot rely on the method validate() of persistent classes that implement Validatable.

a) What is the use of validate(), if I cannot rely on it?
b) What is the best approach to validate data before making it persistent, when I don't want to use database functional (constraints) for it?

TIA your Hibernate Beginner Chris :-)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 9:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Can you eloborate on what you mean by
Quote:
cannot rely on the method validate() of persistent classes that implement Validatable
.

Validatable is pretty limited in scope. You are not allowed to access the underlying session in any way during Validatable.validate(); this includes causing lazy associations to load. Thus validatable is good for things like null checks and simple attribute value checks. In general, it is advisable to not even attempt to read across associations of any type in that validate method.

You could utilize Interceptor for some more advanced validations (I use this approach currently passing the entities off to a validation framework). I have been using this approach for about 9 months, and what I've found is that it is somewhat limiting to perform this at thie level of the app; specifically talking about business validations.

If you go this route of tieing validations to you data acess, I would highly recommend partitioning you validation checks into (a) data checks and (b) business checks. Data checks would be things like a field can never be null, or a start date has to be before an end date; things which are *ALWAYS* true. I made the mistake initially of tieing all my validations here, including business checks, and am regretting it (and changing it).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 9:55 am 
Newbie

Joined: Tue Mar 16, 2004 7:14 am
Posts: 3
Location: Aachen, Germany
I was referring to this two from the reference documentation:
Quote:
Unlike the callback methods of the Lifecycle interface, validate() might be called at unpredictable times. The application should not rely upon calls to validate() for buisness functionality.


Thanks for your detailed answer, I will try your approach tomorrow after the unit tests for my schema are ready.

chris


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.