-->
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 "code" relationships
PostPosted: Thu Mar 08, 2007 7:32 pm 
Newbie

Joined: Mon Oct 23, 2006 11:03 pm
Posts: 17
Many database schemas contain "code" tables that map
internal attribute values to external display strings.
For instance:

Code:
create table CODE_OS_TYPE
(
    OS_TYPE             varchar2(4)     not null primary key,
    DESCRIPTION         varchar2(30)    not null
);


Then in your entity tables you store only OS_TYPE code

Code:
create table CR_ASSET
(
    ASSET_ID            integer                 not null,
    OS_TYPE             varchar2(4)             not null,
    ....


When mapping such a schema in Hibernate, what's the
recommended way of mapping these "code" relationships
from within the entity so that the Java object has
access to both the code and description?

In the above example, the CR_ASSET mapping might look like this:

Code:
<class name="Asset">
  <id name="id" column="ASSET_ID" type="long">
    ...
  </id>

  <property name="osType"     column="OS_TYPE" />
  <property name="osDescription"  ???what goes here??? />
  ...


This is one common use-case that doesn't appear to be covered in
the otherwise excellent "Java Persistence with Hibernate".

One option I considered was defining osDescription as a
derived property using the formula= attribute with a
correlated subselect. I'm concerned that this would result
in greatly reduced query efficiency... then again, maybe Oracle's
optimizer is smart enough to convert the subselect to a join.

Anybody have suggestions on how to implement this, or pointers
to where this is described?

Is a correlated subquery the preferred method?


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.