| Author |
check constraint in hibernate using jpa
|
Rosu Thomas
Greenhorn
Joined: Jun 19, 2012
Posts: 15
|
|
hi
i need to set a check constraint for my column (such as.order_status must be either 0 or 1.).........it should give error message if i enter any other integer...
i am new to hibernate with jpa.............so please help me asap..............
thanks in advance
|
 |
Josip Juric
Greenhorn
Joined: Nov 23, 2012
Posts: 2
|
|
Hi,
You could abuse the @min and @max annotations.
See below link for examples
http://docs.jboss.org/hibernate/validator/4.0.1/reference/en/html_single/
Example:
Example 2.13. Driver
Regards,
Josip
|
 |
Rosu Thomas
Greenhorn
Joined: Jun 19, 2012
Posts: 15
|
|
hi,
i tried like this
@Min(0)
@Max(2)
public int getGi_qa_status() {
return gi_qa_status;
}
public void setGi_qa_status(int gi_qa_status) {
this.gi_qa_status = gi_qa_status;
}
but still that column is accepting numbers not within that range..i tried @ not null annotation also............that also not working.........................i am using java version 6...and added following jar file.......hibernate-validator-4.1.0.Final
please help me :'(
|
 |
Rosu Thomas
Greenhorn
Joined: Jun 19, 2012
Posts: 15
|
|
hi thanks for helping me................i got it.................hibernate 3.5 and above only support hibernate validations...................................................have a great day
|
 |
 |
|
|
subject: check constraint in hibernate using jpa
|
|
|