• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

check constraint in hibernate using jpa

 
Rosu Thomas
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks for helping me................i got it.................hibernate 3.5 and above only support hibernate validations...................................................have a great day
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic