-->
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: Group sequence flow control and class constaints
PostPosted: Mon Sep 06, 2010 9:29 am 
Newbie

Joined: Thu Mar 27, 2008 12:07 pm
Posts: 3
Hello,

I am using two types of constraints: field and class constraints, and I want to run the field constraints first. Since there is not a predefined order for these constraints, I need to create an sequence. Is there a way to create this order without specifying a group for the field or class constraints? Is there a predefined "group" for class constraints?

Another thing that I would like to know is if there is a way to control the flow of the sequence. If the field validations fail I don't want to run the class validations. I don't want to replicate validation code, e.g. check if fields are null.

A simple example of this:

Code:
@CheckMyClass
public class MyClass {
   
    @NotNull
    private Long longA;
   
    @NotNull
    private Long longB;
}


The validator checks if longA is less than longB, otherwise will fail the validation. I don't want to check for nulls again:

Code:
public class CheckMyClassValidator {
  (...)
  public boolean isValid(MyClass myClass, ConstraintValidatorContext constraintValidatorContext) {
        if(myClass.getLongA() < myClass.getLongB()){
            return true;
        }
        else {
            return false;
        }
    }
}


Top
 Profile  
 
 Post subject: Re: Group sequence flow control and class constaints
PostPosted: Tue Sep 07, 2010 7:15 am 
Hibernate Team
Hibernate Team

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

there is no pre-defined class constraint group. Jsut create one and add it to the end of your group sequence. If you now validate your sequence first your fields get validated in the order you defined and lastly the class constraint.
This way validation will also automatically stop in case a field constraint will fail. Class constraint will only be evaluated if all other groups in the sequence passed.

--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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.