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-2It 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.