-->
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.  [ 1 post ] 
Author Message
 Post subject: How to get a many-to-many association as a map?
PostPosted: Fri Apr 08, 2011 6:24 am 
Newbie

Joined: Fri Apr 08, 2011 6:09 am
Posts: 1
Hi,
I have two entities A and B with a many-to-many relation. The relation has an attribute ATTRIBUTE of type Integer.
These entities represented by three tables on the DB level.
Table TAB_A with primary ID_A corresponds to the entity A.
Table TAB_B with primary ID_B corresponds to the entity B.
Table TAB_A_B with composite primary key (ID_A,ID_B) and a field ATTRIBUTE for the attribute of the relation represents the relation.
On the Java level I would like to get only two classes
ClassA for the entity A and
ClassB for the entity B.
ClassA has an attribute
Map<ClassB,Integer> mapBs
for the relation.
I tried
Code:
@ElementCollection
@CollectionTable(name="TAB_A_B",joinColumns=@JoinColumn(name="ID_A"))
@Column(name="ATTRIBUTE")
@MapKeyJoinColumn(name="ID_B", referencedColumnName="ID_B")
private Map<ClassB,Integer> mapBs
But Hibernate generated SQL
Code:
   select
        ID_A,
        ATTRIBUTE,
        TAB_A_B _KEY
    from
        TAB_A_B
    where
        ID_A=?
and told me that
Code:
column TAB_A_B _KEY does not exist
.
So the question is as follows.
Is it possible to force Hibernate to make only two classes with an map attribute?
And how if the answer is yes.
Thank you in advance,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.