[hibernate-dev] On possible extensions for the validator

Hardy Ferentschik hibernate at ferentschik.de
Mon Oct 18 05:11:54 EDT 2010


I was also thinking about a generic class level @CrossValidation  
constraint. I think Emmanuel and I
are thinking about the same thing here:

@CrossValidations({
    @CrossValidation(forGroup=BankAccount.class),
    @CrossValidation(forGroup=ContactDetails.class)
})
public class BankAccountNumber {

    @ExactlyOneNull(groups=BankAccount.class)
    public String getIBAN() {
       return IBAN;
    }

    @ExactlyOneNull(groups=BankAccount.class)
    public String getAccount() {
       return account;
    }


    @ExactlyOneNull(groups=ContactDetails.class)
    public String getHomeNumber() {
       return homeNumber;
    }

    @ExactlyOneNull(groups=ContactDetails.class)
    public String getWorkNumber() {
       return workNumber;
    }
}

Using groups (or maybe payloads!?) you can have multiple cross validations  
of the same type within one entity.

--Hardy


On Mon, 18 Oct 2010 09:48:16 +0200, Emmanuel Bernard  
<emmanuel at hibernate.org> wrote:

>
> On 16 oct. 2010, at 10:56, Dag Hovland wrote:
>
>> On 15/10/10 13:33, Emmanuel Bernard wrote:
>> (...)
>>> That being said, I wonder whether you can write your approach atop a  
>>> generic class-level constraint @CrossValidation that would look for  
>>> the properties annotations and behave as expected. That would be a  
>>> nice way to offer both world to the users. You will need to "group"  
>>> cross field constraints though: as I see it on the paper, you can only  
>>> have one group of cross level constraint for a given constraint type  
>>> per class.
>>
>> I do not really understand this. Can you give an example?
>
> class BrokenModel {
>    @AtLeastOneNotNullAmongst(Group1.class)
>    A getA() { ... };
>    @AtLeastOneNotNullAmongst(Group1.class)  
> @AtLeastOneNotNullAmongst(Group2.class)
>    B getB() { ... };
>    @AtLeastOneNotNullAmongst(Group2.class)
>    C getC() { ... };
> }
>
> A or B must be not null and B or C must be not null.
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev




More information about the hibernate-dev mailing list