-->
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.  [ 2 posts ] 
Author Message
 Post subject: Multiple identical class level constraints
PostPosted: Mon Nov 01, 2010 4:46 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

Just wondering how to create multiple identical class level constraints? I find myself writing class level constraints when the value of one property depends on another. E.g.
XLowerThanY
XMustExcludeY
XBeforeY
etc

However, when I need to do multiple XLowerThanY, there doesn't seem an option to do something like this
@constraints{
@XLowerThanY(x="productId",y="productType"),
@XLowerThanY(x="otherId",y="otherType"),
}

or is there?

Marc


Top
 Profile  
 
 Post subject: Re: Multiple identical class level constraints
PostPosted: Mon Nov 01, 2010 8:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
The recommended way of dealing with this is to have an inner List definition in your constraint:

Code:
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
public @interface XLowerThanY {
...
   @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
   @Retention(RUNTIME)
   @Documented
   @interface List {
      XLowerThanY[] value();
   }
}


In this scenario you can then use @XLowerThanY.List({...}) to specify multiple XLowerThanY constraints.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.