-->
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.  [ 1 post ] 
Author Message
 Post subject: mapping a foreign-key constrained one-to-one enum
PostPosted: Wed Feb 16, 2005 2:15 pm 
Newbie

Joined: Sat Nov 20, 2004 2:26 pm
Posts: 5
Hibernate version:2.1

Mapping documents:unknown

Name and version of the database you are using:MySQL 4.1

I'm having trouble figuring out how to map a foreign-key one-to-one typesafe relationship. The details are as follows:

table message
-----------------
message_id (primary key, auto_inc)
message
message_type

table message_types
------------------------
message_type_id (primary key, auto_inc)
message_type_name

where
message.message is a String containing a message
message.message_type is an int - the foreign key of message_types
message_types.type_name is a String

I would like message_types to be a typesafe enum. My problem is figuring out how to map the message.message_type int without exposing the int to the outside world.
That is, I can't make the getter
public int getMessageType()
because it needs to be
public MessageType getMessageType()

I would rather not make MessageType a hibernate-persisted object, because that forces a public constructor and a public getId() method. In fact, if there were a way to simply look up the id from the table using the string from MessageType, I'd love to see it!

-James


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

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.