Hibernate, mapping problem

R

robert

Hello, i am trying to make my project for studies using hibernate but
i've come across a problem i cant solve nor can found any help in
tutorial. Well i have classes and mappings more less like this

class X{
map<AB, Y> ABs;
map<AC, Y> ACs;
}

class Y{
string info
}

class A {
map <X, Y> Xs;
}

class AB estends A{
string info2
}

class AC extends A{
integer amount;
}

with mapping

for X:
<id ... column="X_id"...>

<map name="ABs" inverse="true">
<key column="X_id" not-null="true"/>
<map-key-many-to-many column="A_id" class="AB" />
<one-to-many class="Y"/>
</map>

<map name="ACs" inverse="true">
<key column="X_id" not-null="true"/>
<map-key-many-to-many column="A_id" class="AC" />
<one-to-many class="Y"/>
</map>

for Y
<id ... column="Y_id"...>
......

for A, AB and AC
<class name="A"....>
<id... column="A_id"..>

<map name="Xs">
<key column="A_id" not-null="true"/>
<map-key-many-to-many column="X_id" class="X" />
<one-to-many class="Y"/>
</map>

<union-subclass name="AB".....>
......
</union-subclass>

<union-subclass name="AC".....>
......
</union-subclass>
</class>

Then when i make:
X x= new X(); Y y1...Y y2.... AB ab.... AC ac

ab.Xs.add(x, y1);
ac.Xs.add(x, y2);

and then save all those objects to DB and after that load them then i
see that x have 2 elements in both map ABs and ACs, and from neither
of those maps its possible to benefit, since when iterate over
elements of any of those collections always one is not found and an
exception is thrown.

Furthermore I can say that unfortunately movin Xs collection from
class A to AB and AC (and mapping it twice) gives no effect.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top