-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to persist an enum as a table?
PostPosted: Fri Aug 15, 2008 2:38 pm 
Newbie

Joined: Fri Oct 06, 2006 5:02 pm
Posts: 11
Using @Enumerated for Enum persistence, I get a String representation or an Integer in my database. Nothing prevents me from changing those values directly in the database. However, when my object is loaded I'll get an Exception.

Is there a way to make validation in the DB itself to prevent that value from being changed? Something like persisting my enum type as an entity and forbid this table from being updated? Or setting a restriction in the database (through annotations) so that some field can only accept certain values?

Some ideas:
- To implement a UserType in hibernate so that I can make a custom mapping
- To clone my enum into a Class and then do some code hacking so that the enum can be accepted instead of my class

Any suggestions?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 15, 2008 4:55 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
A column "check" (SQL) is probably a safe bet.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 15, 2008 7:18 pm 
Newbie

Joined: Fri Oct 06, 2006 5:02 pm
Posts: 11
Good idea. I've just read about that, mysql does not support it :-( But it's MYSQL's fault then :-@

So If I'm to enable this in MYSQL I need to use another table (enum as entity) or do some hacking in MysqlDialect from hibernate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.