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: How to map a Map where the key is not in the table
PostPosted: Fri Oct 28, 2005 12:01 am 
Newbie

Joined: Thu Oct 27, 2005 11:42 pm
Posts: 5
I have a class A, that contains a Map. The values of that Map are instances of class B. Class B contains a reference to a class C (many-to-one). The key to the Map is a member of class C.

Classes (they all have the appropriate ids, constructors, setters and getters):
class A {
Map bs;
}

class B {
C c;
}

class C {
String name;
}

Tables:
CREATE TABLE A (
id BIGINT PRIMARY KEY,
description TEXT
);

CREATE TABLE B (
id BIGINT PRIMARY KEY,
aId BIGINT REFERENCES A,
cId BIGINT REFERENCES C,
description TEXT
);

CREATE TABLE C (
id BIGINT PRIMARY KEY,
name VARCHAR(64)
);

So C's HBM is pretty straightforward:
<class name="C" table="C">
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="name" type="text" column="name" />
</class>

B's seems pretty straightforward as well
<class name="B" table="B">
<id name="id" column="id">
<generator class="increment" />
</id>
<many-to-one name="C" column="cId" class="C" lazy="false" />
</class>

But I can't figure out what to do for A's HBM. I think it needs to look something like:
<class name="A" table="A">
<id name="id" column="id">
<generator class="increment" />
</id>
<map name="bs" table="B" lazy="false" fetch="join">
<key column="aId" />
<map-key type="string" formula="???????" />
<one-to-many class="B" />
</map>
</class>

But I can't figure out how to define the formula, or what the alternative representation that doesn't need a formula.

Any thoughts? Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 31, 2005 2:56 pm 
Newbie

Joined: Thu Oct 27, 2005 11:42 pm
Posts: 5
Well, I gave up, and solved the problem by making the object itself the key to the map, rather than the string...


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.