-->
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.  [ 3 posts ] 
Author Message
 Post subject: Two maps in one table
PostPosted: Thu Nov 24, 2005 3:35 pm 
Beginner
Beginner

Joined: Thu Dec 16, 2004 11:54 am
Posts: 26
Location: Brussels, Belgium
I have two maps in a class that I'd like to map to one table.
The both maps are about i18n'zed properties, so that I'm trying to map:
Code:
<map>
    <map-key column="language" type="string"/>
    <element column="label" type="string"/>
</map>
<map>
    <map-key column="language" type="string"/>
    <element column="description" type="string"/>
</map>


Is there a way to have this persisted to the same table with such a schema:
Code:
CREATE TABLE products_i18n (
id_product INT,
locale CHAR(2),
label VARCHAR(255),
description TEXT
)


Thanks,
Alex


Top
 Profile  
 
 Post subject: Consider using business logic
PostPosted: Thu Nov 24, 2005 5:38 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Are the two maps going to have the same set of keys? If you're going to end up with identical sets of keys, then I think what you want to do is to add one map with both columns in your hibernate mapping, then use that map to back two "virtual" maps in your java object. This will reduce the number of selects and the amount of memory required. It does require writing two small implementations of AbstractMap, but that's not hard.

If the two maps are significantly different (one set of languages has labels and another disjoint set has descriptions), then what you propose will work fine.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 9:44 pm 
Beginner
Beginner

Joined: Thu Dec 16, 2004 11:54 am
Posts: 26
Location: Brussels, Belgium
Well what I propose does actually NOT work.
On insert, hibernate tries to insert 2 rows, one with the label and one with the description for the same map-key.
The two maps should always contain the same keys. Only I wanted to have description lazy, since it shouldn't always be needed.
But I thought that I'll need to go for something like a single backing map...
Thanks for the reply, while I had hoped that some kind of "funky" mapping could have had solved my problem with a hbm-only solution...
Alex


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