A simple way would be to do it like this:
public void setAvailableCount(Integer availableCount) { if(availableCount < 0){ throw new IllegalArgumentExcpetion("Must be possive value"); } this.availableCount = availableCount; }
This will not create a database restriction.
change
If you use JPA annotations, you can create the @ PrePerist-Annotated method:
@PrePersist public void something(){ if(availableCount < 0){ throw new IllegalArgumentExcpetion("Must be possive value"); } }
Fix error, loading should work.
source share