-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to access Validator Annotation MetaData programatically?
PostPosted: Sat May 05, 2007 8:45 am 
Newbie

Joined: Sat May 05, 2007 8:11 am
Posts: 2
Hibernate version:
hibernate-3.2, hibernate-annotations-3.3.0.GA,
hibernate-validator-3.0.0.GA

Mapping documents:
none (annotations)


Hi everyone,

For testing I have made an annotated class like so:

Code:
import javax.persistence.*;
import org.hibernate.validator.*;

@Entity
@Table(name="person")
public class Person
{
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE)
    long id;

    @Column( length=128 )
    @Length( min=5, max=128 )
    @Email
    String email;
}


How would I go about obtaining the Annotation Metadata from this class from within my program?

I'd like to write a small presentation framework and that needs
to learn about the constraints for each field to do its thing.

I figured out how I can get at the basic Column's via Configuration.getClassMapping(..).getIdentityTable(..).getColumn(..).
But those only seem to give me the classname and @Column( length ),
most other getters return null for my little testclass (even getSqlType(), i wonder why?).

But how do I get the data for @Length( min/max ), @Email, @Id and
other Annotations?


Any help would be very appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 05, 2007 10:00 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
With regular Java Reflection: class.getAnnotations() etc.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 05, 2007 11:05 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
In the meanwhile Christian is right, check the properties annotations annotated with @ClassValidator

The spec group is willing to provide a metadata API though, so it probably will be possible to avoid the manual annotation checking in the future.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 05, 2007 12:56 pm 
Newbie

Joined: Sat May 05, 2007 8:11 am
Posts: 2
Thank you christian and emmanuel.

I'll go for it with direct annotation access for now, not so nice imho because the annotation semantics may change in the future(?) but at least that's
gonna work in a reasonable straightforward fashion. :-)

I'm definately looking forward to the metadata API, that might ease the integration of other components with validator and hibernate in general.

Without knowing much about the specs that you're targeting I'd personally also like to see a more or less generic way to add own meta-data to be accessed via the same API. Maybe that's even possible already and I just don't know?

In my specific case I'd use such "meta-annotations" to provide hints
to the presentation layer about things like preferred size and order
of the input widgets and to further augment the available information
about field types with stuff like "isPassword" (to create a special password-dialog).

Anyways, thanks for the pointer, for now I'll move on with what we have today.


regards, raz


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