-->
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.  [ 5 posts ] 
Author Message
 Post subject: why MySql Enum mapping needs it's own table?
PostPosted: Mon Sep 28, 2009 11:31 am 
Newbie

Joined: Mon Mar 30, 2009 2:47 pm
Posts: 15
Hello guys!
i've been tried to map Java 5 enum type to mysql enum type and came accross this article http://weblog.dangertree.net/2007/09/23/mapping-java-5-enums-with-hibernate/ and couldn't understand why there should be a table to hold the enum details or elements.i was expecting it to be map to a field in the table.the other version i got is to map a string property to the enum like suggested here http://stackoverflow.com/questions/1076604/mysql-enum-with-hibernate but it doesn't seem to be what i want.is there any other way to achieve that?THanks for reading


Top
 Profile  
 
 Post subject: Re: why MySql Enum mapping needs it's own table?
PostPosted: Mon Sep 28, 2009 2:52 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi highjo,

highjo wrote:
... and couldn't understand why there should be a table to hold the enum details or elements.i was expecting it to be map to a field in the table...


You should probably read this to understand why it is done this way: http://en.wikipedia.org/wiki/Database_normalization

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: why MySql Enum mapping needs it's own table?
PostPosted: Sun Nov 22, 2009 6:54 pm 
Newbie

Joined: Sun Nov 22, 2009 6:42 pm
Posts: 7
Hi Froestel,

I see why someone would like to put the Enum details in another table. However, wouldn't that become expensive since it'll require you to perform a join? Sure, the Enum table is small, but still..

And even if it's wrong in principle, is there a way to achieve what the original poster asked? Since I'm sure my enum is never going to change and is only used in 1 class, I'd rather have it map to an enum column in the database.

If I don't specify the type of my Enum field in the xml mapping file, I see that Hibernate is adding a column in my db with type 'tinyblob' and a cryptic value. Yet it manages to correctly map the cryptic value back to the appropriate Enum in my POJO. It does what I want it to do, but doesn't seem ideal. I want the db column to be an enum and the values to be the possible enum values (strings). Can you help me achieve this? BTW, I'm using MySQL.

Thanks!


Top
 Profile  
 
 Post subject: Re: why MySql Enum mapping needs it's own table?
PostPosted: Mon Nov 23, 2009 12:29 am 
Newbie

Joined: Sun Nov 22, 2009 6:42 pm
Posts: 7
It seems the 'cryptic' value i was talking about is the serialized version of the Enum... It seems any Serializable class for which there's no explicit mapping defined will be pushed into the DB as a tinyblob...


Top
 Profile  
 
 Post subject: Re: why MySql Enum mapping needs it's own table?
PostPosted: Mon Nov 23, 2009 6:17 am 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi rodrigo.ipince,

have you tried to map the enum as a component? This could probably work.

Anyway, why care about the way the value is stored in the database? This should usually not matter.

CU
Froestel

P.S.: BTW, it is not necessarily a tinyblob that is used. You can determine the size by passing an appropriate long attribute value in the mapping.

_________________
Have you tried turning it off and on again? [Roy]


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