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
|