java ee - Specifying Constraints on a field representing a Date in an entity JPA -


i have set constraint on fields "heurefin" & "heuredebut" of entity intervention, wonder how precise constraint : heurefin>heuredebut ?? here entity :

public class intervention implements serializable {     private static final long serialversionuid = 1l;     @id     @size(min = 1, max = 50)     @column(name = "idintervention", length = 50)     private string idintervention;     @basic(optional = false)     @notnull     @column(name = "heuredebut", nullable = false)     @temporal(temporaltype.timestamp)     private date heuredebut;     @basic(optional = false)     @notnull     @column(name = "heurefin", nullable = false)     @temporal(temporaltype.timestamp)     private date heurefin; } 

is possible, or should process constraint somewhere else ?

thank in advance :)

it not possible @ member level. should use class level constraints , implementing own constraint validator (which takes instance parameter of isvalid() method, facilitating comparison).

create custom validator:

public class hourrangevalidator implements constraint<interventionhourrange, intervention> { 

and implement isvalid method comparison logic need.

create custom annotation:

@constraintvalidator(hourrangevalidator.class) @target(type) @retention(runtime) public @interface interventionhourrange {     string message() default "{your.error.message}";     string[] groups() default {}; } 

and annote entity:

@interventionhourrange public class intervention implements serializable { 

see http://docs.jboss.org/hibernate/validator/4.0.1/reference/en/html/validator-customconstraints.html


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -