-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: @Check and Enums
PostPosted: Wed May 23, 2007 10:55 am 
Newbie

Joined: Wed Mar 28, 2007 4:00 pm
Posts: 7
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 3:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Actually if you use @Min and @Max on the same property, one of the check will be overriden by the other.
Hibernate core is missing the ability to addCheckConstraint() (and to the AND operation).
This can be tedious if DB do not support the same AND syntax ( I'm not familiar enough with that )

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.