The JavaDoc for @Check states that a check constraint can be defined at class, property, and collection level. The check is applied when defined at the class level, but its shortcoming is that only one check can be defined at the class level. It seems @Check is ignored when defined at the property level. Is there a way to have multiple checks? I do get multiple checks when using @Min or @Range, but those are defined at the property level and are included in the column definition. Could the argument for @Check be changed from String to String[]?
I was going down this check path because I like to use Enums. The db admin doesn’t like them because they are not enforced in the database only in the application. He will allow them if they are saved as strings rather than ordinally, but also with a check constraint. I can manually add checks external to the generated DDL, but it would be nice to have a validator annotation for enums that would add a check, so that if the Enum changes in the development phase, the check would change accordingly.
I am tempted to defined my own validator annotation. The check would be different whether it is STRING or ORDINAL. However, I don’t know how to get the information from the @Enumerated(EnumType.STRING) for use in my *Validator.class. Can someone point me in the right direction?
I’m using:
Hibernate 3.2.2.ga
Annotations 3.2.0.ga
Tools 3.2.0.beta8
Thanks.
|