-->
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.  [ 3 posts ] 
Author Message
 Post subject: The Constraint composition with groups for each constraint
PostPosted: Fri Jun 15, 2012 1:49 am 
Newbie

Joined: Fri Jun 15, 2012 1:20 am
Posts: 3
Location: Bangkok, Thailand
Hi All,

I'm trying to use the Constraint composition and would like to define the group for each composited constraint as the following example: -

The Composite Constraint
Code:
    @Target({
        ElementType.FIELD,
        ElementType.METHOD,
        ElementType.PARAMETER,
        ElementType.TYPE,
        ElementType.ANNOTATION_TYPE
    })
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @DummyValid1(group = Group1.class)
    @DummyValid2(group = Group2.class)
    @Constraint(validatedBy = {})
    public @interface DummyCompositeValid {

        String message() default "The bean is invalid.";
   
        Class<?>[] groups() default {};

        Class<? extends Payload>[] payload() default {};
    }


The data bean
Code:
    @DummyCompositeValid
    public class DummyBean {
        //Fields declaration, Setter and Getter
    }


The business validation method
Code:
    this.validator.validate(dummyBean, Group1.class, Group2.class);


The result is the dummyBean has not been validated. I'm confused that since the group is worked well when it is defined directly without the composite constraint as the following: -

The data bean
Code:
   
    @DummyValid1(group = Group1.class)
    @DummyValid2(group = Group2.class)
    public class DummyBean {
        //Fields declaration, Setter and Getter
    }


Could you please help to advise and explain further? Thank you very much for your help in advance. I'm looking forward to hearing from you soon.

Regards,

Charlee Ch.


Top
 Profile  
 
 Post subject: Re: The Constraint composition with groups for each constraint
PostPosted: Fri Jun 15, 2012 4:32 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

what you are trying to do is not possible. The composing constraints are inheriting the groups from the main annotation. This is part of the spec:

Quote:
Groups from the main constraint annotation are inherited by
the composing annotations. Any groups definition on a composing annotation is ignored. Likewise, payload from
the main constraint annotation is inherited by the composing annotations. Any payload definition on a composing
annotation is ignored.


Depending on what you are trying to achieve you need to take a different route.

--Hardy


Top
 Profile  
 
 Post subject: Re: The Constraint composition with groups for each constraint
PostPosted: Fri Jun 15, 2012 4:38 am 
Newbie

Joined: Fri Jun 15, 2012 1:20 am
Posts: 3
Location: Bangkok, Thailand
Dear Hardy,

Thank you for your kindly explanation.

Regards,

Charlee Ch.


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