-->
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.  [ 7 posts ] 
Author Message
 Post subject: Can I create a validator from an already existing annotation
PostPosted: Mon Jun 18, 2007 10:50 am 
Beginner
Beginner

Joined: Fri Jan 14, 2005 7:47 am
Posts: 37
Location: Spain
Hi,

I want to write something like this:

Code:
@Column(length=40, nullable=false)
private String name;


instead of this:

Code:
@Length(max=40) @NotNull
@Column(length=40, nullable=false)
private String name;


That is, I want that Hibernate validator validates from a JPA annotation, or
from whatever annotation although I cannot change the source code of it.

Is this possible ?

Thank you in advance


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 11:08 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
nope

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 11:41 am 
Beginner
Beginner

Joined: Fri Jan 14, 2005 7:47 am
Posts: 37
Location: Spain
Hi Emmanuel,

why not in addition of ...

Code:
@ValidatorClass(ColumnValidator.class)
@Target(METHOD)
@Retention(RUNTIME)
@Documented public
@interface Column {
...
}


for linking annotation to the validator class, we add the option:

validators.xml:

Code:
<validator annotation="javax.persistence.Column" class="mypackage.ColumnValidator"/>


Or, if you hate XML, something like this:

Code:
@AnnotationToValidate(javax.persistence.Column.class)
public class CapitalizedValidator implements PropertyConstraint {

  public boolean isValid(Object value) {
  ...
  }

}


What do you think ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 6:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The idea is interesting, but really the JPA provider should consume the data from Validator. This is how we intend it in JSR-303. Several annotations expressing the same constraint will fragment things more than helping.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 6:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The idea is interesting, but really the JPA provider should consume the data from Validator. This is how we intend it in JSR-303. Several annotations expressing the same constraint will fragment things more than helping.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 5:53 am 
Beginner
Beginner

Joined: Fri Jan 14, 2005 7:47 am
Posts: 37
Location: Spain
emmanuel wrote:
the JPA provider should consume the data from Validator.

It's an option. But ALL JPA implementations will need to understand Hibernate validator.

emmanuel wrote:
This is how we intend it in JSR-303.

This is good news, at least for me.

Thanks


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.  [ 7 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.