-->
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: Problems with Many to Many Mapping over a non PK Column
PostPosted: Sat May 16, 2009 11:45 am 
Newbie

Joined: Sat May 16, 2009 11:01 am
Posts: 2
Hi, I'm having some issues with a Many To Many Mapping.
I have two Tables (TABLE1, TABLE2) each having a Primary Key named ID and another Column named NUMBER.
Additionally I have a Join Table (TABLE1_TABLE2) with two columns NUMBER1 and NUMBER2.
What I want is a Many To Many Join using the NUMBER columns and not the ID columns.
I tried this, but it's not working...it always uses the ID columns no matter what I try.

@ManyToMany
@JoinColumn(name="NUMBER", referencedColumnName="NUMBER")
@JoinTable(joinColumns=@JoinColumn(name="NUMBER1"),
inverseJoinColumns=@JoinColumn(name="NUMBER2"))

and

@ManyToMany
@JoinColumn(name="NUMBER")
@JoinTable(joinColumns=@JoinColumn(name="NUMBER1"),
inverseJoinColumns=@JoinColumn(name="NUMBER2", referencedColumnName="NUMBER"))

I can't find anything about this usecase for a Many To Many Mapping.
Hopefully somebody of you can help me.
Frank


Top
 Profile  
 
 Post subject: Re: Problems with Many to Many Mapping over a non PK Column
PostPosted: Sun May 17, 2009 12:28 pm 
Newbie

Joined: Sat May 16, 2009 11:01 am
Posts: 2
I think the correct Annotation is:

@ManyToMany
@JoinTable(joinColumns=@JoinColumn(name="NUMBER1", referencedColumnName="NUMBER")),
inverseJoinColumns=@JoinColumn(name="NUMBER2", referencedColumnName="NUMBER"))

But now I'm facing the next problem...
Im trying to perform a many-to-many self-join,but with the Example above i get an error that says:
Duplicate property mapping ....

It looks like you can't have a many-to-many relationship to the same object using a non primary key column!!!

Is that a bug in hibernate??


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.