-->
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: Property/Column length attribute used as constraint ever?
PostPosted: Wed Jun 07, 2006 11:31 am 
Newbie

Joined: Tue Jun 06, 2006 2:18 pm
Posts: 2
Be warned: here comes a newbie. :-)

The property/column element used in the mapping file might contain the length attribute, say like this:

Code:
<property name="hello" column="greetings" length="20" type="string" />



Is it ever used to constraint the length of that field by hibernate, say, for validation purposes before it gets persisted? If not, how do I go about having hibernate validates the length of those fields?

Thanks.


Top
 Profile  
 
 Post subject: Re: Property/Column length attribute used as constraint ever
PostPosted: Wed Jun 07, 2006 12:01 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:08 pm
Posts: 26
mygear wrote:
Be warned: here comes a newbie. :-)


No worries man.

mygear wrote:
The property/column element used in the mapping file might contain the length attribute, say like this:

Code:
<property name="hello" column="greetings" length="20" type="string" />



Is it ever used to constraint the length of that field by hibernate, say, for validation purposes before it gets persisted?


The length attribute is discussed in the online Hibernate manual: http://www.hibernate.org/hib_docs/v3/reference/en/html/toolsetguide.html#toolsetguide-s1-2

It is used to define column widths (of say a VARCHAR column) in your database if you use Hibernate's schema generation tool to create your database.

As far as I know, it is not used for validating the length of data entered by a user into say a String object.

mygear wrote:
If not, how do I go about having hibernate validates the length of those fields?


I don't know of any Hibernate-provided mechanism for data validation. You'll have to do it yourself. One library that might be useful to you is Apache Commons Validator. I've never used it but it looks like it has some useful features.

If you found this advice helpful, can you please give me a credit? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 09, 2006 1:04 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:08 pm
Posts: 26
mygear, did you try Apache Commons Validator yet?


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.