-->
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.  [ 5 posts ] 
Author Message
 Post subject: Duplication when using Validator and Annotations
PostPosted: Mon Nov 05, 2007 7:01 pm 
Newbie

Joined: Wed Jan 31, 2007 5:42 pm
Posts: 2
Location: Beaverton, Oregon
I am in the process of plugging the hibernate validator into our application, but I was surprised to find that in order to make it work I will have to add the new @NotNull and @Length annotations. Our application already uses the @Column(name="foo", length=X, nullable=false) annotation so why can't the validator just read the @Column annotations instead of looking for new ones?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 07, 2007 10:19 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I envision it being done the other way around, ie having JPA reading the metadata form validator.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 07, 2007 3:43 pm 
Newbie

Joined: Wed Jan 31, 2007 5:42 pm
Posts: 2
Location: Beaverton, Oregon
Interesting.

I think my original post was a little blunt :)

My project already uses JPA and Hibernate annotations, so we already have the @Column annotations with nullability and length set on them. These parameters are used to generate the DDL, which works just brilliantly. Now we want to add validation to the app and it seems that validation needs a whole new set of annotations?

I guess what I am asking is, what is the difference, both in terms of what the hibernate tools sees, and what hibernate runtime sees between the following declarations:

@Column(name="Foo", length=20, nullability=false)
private String name;

and

@Column(name="Foo")
@Length(max=20)
@NotNull
private String name;

I prefer the terseness of the former declaration, but the Hibernate Validator doesn't appear to look at the @Column annotation to derive max length and nullability information.

Also, what would be the result if conflicting parameters were set?

i.e.

@Column(name="Foo", length=20, nullability=true)
@Length(max=40)
@NotNull

Would the hibernate toolset only read the column annotation to generate the DDL, and leave the Validator to use the Length and NotNull annotations, or would the presence of a Length annotation trump the length parameter in the Column annotation?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 09, 2007 6:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
For the first example, there is no difference

I don't want to infer a global object level constraint from a DB specific annotation.

If you have conflicting annotations, that's not really defined, but the current implementation will use the validation annotations in priority

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 12, 2007 10:04 am 
Beginner
Beginner

Joined: Sun Sep 30, 2007 2:58 pm
Posts: 26
More informations at:
http://opensource.atlassian.com/projects/hibernate/browse/HV-43

Regards,
Leonardo


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