-->
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.  [ 2 posts ] 
Author Message
 Post subject: Transparent lookup table values as map keys
PostPosted: Tue Jun 21, 2005 3:19 pm 
Newbie

Joined: Wed Aug 25, 2004 11:16 pm
Posts: 12
Location: San Francisco, CA
I'm trying to get hibernate to handle using a lookup table for may keys in a transparent manner. I keep getting close, but I haven't been able to get the exact behavior I need/want. It might not be possible, but it sure seems like it could be (or so I hope!).

At a high level: I want map keys to be references to values in a lookup table, but, in my code look like they are simple Strings. That is, I want hibernate to persist references to the lookup table by id, but map the keys to their lookup values when hydrating the classes. I'll explain in more detail...

The tables directly involved look like this:

Code:
-- this is the lookup table (mapped to Report200LineItem)
create table report_200_line_items (
    id int identity not null,
    name varchar(48) not null unique,
    primary key (id)
)

-- this is a map entry which references the lookup table via item_name (mapped to LineItemEntry)
create table line_item_entries (
    id int identity not null,
    code varchar(12) not null,
    amount numeric(19,2) not null,
    line_item_prefs_id int null,
    item_name int null,
    primary key (id)
)

-- this is the parent class which 'has' a map of line_item_entries (mapped to LineItemPreferences)
create table line_item_prefs (
    id int identity not null,
    min_charge numeric(19,2) null,
    primary key (id)
)

alter table line_item_entries add constraint FK173229CF8AB576F0 foreign key (item_name) references report_200_line_items

alter table line_item_entries add constraint FK173229CF2BC26970 foreign key (line_item_prefs_id) references line_item_prefs


I want the Java class that line_item_entries maps to to look like this:

Code:
public class LineItemPreferences {
    // <getters/setters omitted for brevity>
    private Integer id;
    private BigDecimal minimumCharge;
    private Map<String, LineItemEntry> lineItems; // the String is the textual name from the lookup table
    // [A] private Map<Report200LineItem, LineItemEntry> lineItems;
}


Note that the line marked with the [A] works just fine, it's the line before it that I want though. Remember, in my code, when I'm using this class, I want the fact that my map-key is a reference to a lookup table to be transparent.

Here is the relevant mapping information (which works when I'm using the code marked by [A]):

Code:
<class name="Report200LineItem" table="report_200_line_items">
    <id name="id" column="id" type="java.lang.Integer">
        <generator class="identity" />
    </id>
    <property name="name" column="name" type="string" length="48" not-null="true" unique="true"/>
</class>

<class name="LineItemPreferences" table="line_item_prefs">
    <id name="id" column="id" type="java.lang.Integer">
        <generator class="identity" />
    </id>
    <property name="minimumCharge" column="min_charge" type="big_decimal" />
    <map name="lineItems" table="line_item_entries" lazy="false" cascade="all,delete-orphan">
        <key column="line_item_prefs_id" />
        <map-key-many-to-many class="Report200LineItem" column="item_name" />
        <one-to-many class="LineItemEntry" />
    </map>
</class>
   
<class name="LineItemEntry" table="line_item_entries">
    <id name="id" column="id" type="java.lang.Integer">
        <generator class="identity" />
    </id>
    <property name="code" column="code" type="string" length="12" not-null="true" />
    <property name="amount" column="amount" type="big_decimal" not-null="true" />
</class>


Is there a way to acheive the trasparency of the lookup table that I desire? If so, what must I do to my mapping to make it happen?

*Any* pointers or assistence would be a life-saver at this point.

Christian

FYI: I'm using Hibernate 3.0.5 against MS SQL Server 2000 on a Java 1.5 SDK.


Top
 Profile  
 
 Post subject: Did you find an answer
PostPosted: Sun Mar 04, 2007 5:33 am 
Newbie

Joined: Sun Mar 04, 2007 5:19 am
Posts: 8
hey xianpants:

I have a similar problem but not as complicated as yrs, I need to make the lookup table transparent in its refrencing class
for example


table (status) ----- lookup table
column -> ID
column -> status (married, single, etc)

table (person)
column -> ID
column -> name
column -> status -- which is a foriegn key to the table status

i'm want to see the status as string in my application , but hibernate persists its ID

can you help me in that?
and also could you please tell me if you found a solution to yr problem


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