Re: [Hibernate] How to map "decode" tables?



I guess it's not covered because it'is not possible in the way you want to do it.

The most obvious way to do this is the create a class (and mapping) that wraps the OS_TYPE and the description and use this class for the attribute type in Asset.

BTW the term you'll want to use for searching is 'lookup table'.

Hope this helps,
Axel

Jim Garrison wrote:
Many database schemas contain "code" tables that map
internal attribute values to external display strings.
For instance:

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

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:

<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 (if poorly indexed) "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?
.



Relevant Pages

  • Re: [Hibernate] How to map "decode" tables?
    ... internal attribute values to external display strings. ... When mapping such a schema in Hibernate, ... correlated subselect. ...
    (comp.lang.java.databases)
  • [Hibernate] How to map "decode" tables?
    ... Many database schemas contain "code" tables that map ... When mapping such a schema in Hibernate, ... from within the entity so that the Java object has ... correlated subselect. ...
    (comp.lang.java.databases)
  • Re: Master-Detail
    ... Hibernate das neben den Annotations auch verwendet und nicht ... "Without describing any physical mapping, ... nochmaligem Lesen) m.E. gar nicht vor, ob Join table oder nicht, nur wie die ...
    (de.comp.lang.java)
  • Hibernate 3.0 rc1: loading the mapping is soo slow, what can I do?
    ... I am a new hibernate user and I noticed that the loading of the ... mapping takes currently ages. ... I have only 30 mapped classes and every ... Configuration config = new Configuration.configure(new ...
    (comp.lang.java.databases)
  • Re: J2EE or just JSP/Servlet?
    ... >>Hibernate is brilliant. ... > Does Hibernate look at your database and your class definitions and ... existing object model and tries to create a valid mapping between the two. ... Hibernate uses reflection in several places. ...
    (comp.lang.java.programmer)