-->
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.  [ 4 posts ] 
Author Message
 Post subject: self-referencing many to many conflicting id columns
PostPosted: Sun Oct 17, 2004 2:07 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

In a dating application I have a class: Subscriber and I need to reference favourite (other) Subscribers in the system for a particular Subscriber. It seems most logical to self reference the class object in a many to many way.

I use the following xdoclet code in my Subscriber class:

Code:
@hibernate.set name="bookmarks" table="Bookmarks" cascade="save-update" inverse="true" lazy="true" order-by="UserName asc"
@hibernate.collection-key column="SubscriberID"
@hibernate.collection-many-to-many class="packagename.business.entities.Subscriber"
column="SubscriberID"


I'm getting a
Code:
net.sf.hibernate.MappingException: duplicate mapping for property: packagename.business.entities.Subscriber

, when I try to generate the database from the ant task. Presumably it doesn't work using regular Hibernate either. You would want to specify some alias name.

If somebody can offer advice, thanks!

Marc


Top
 Profile  
 
 Post subject: Does anybody have any ideas?
PostPosted: Fri Oct 29, 2004 7:23 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Buehler, Buehler?

Kind regards,

Marc


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 12:18 pm 
Regular
Regular

Joined: Tue Sep 28, 2004 6:34 pm
Posts: 50
I haven't tired to create self-referencing many-2-many - maybe someone did?

But you may decompose many-2-many into many-2-one + one-2-many.
Sth. like: http://adigio.com/blogs/christian/archi ... manyt.html

Lukasz


Top
 Profile  
 
 Post subject: That would work, but
PostPosted: Wed Nov 10, 2004 5:00 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
That would work. In your example "Meeting" is a logical object that seems to have a place in the domain. In my case, when you creating intermediary objects for self referencing you would get objects like "BlockedUser" and "FavouriteUsers". Actually, I would be creating objects based on relational table structure in stead object orientation. I suppose I could just create the tables and reference them in my hibernate.xml. I believe that still leaves me with the fact that with self referencing I have two identical unique keys. And I just love that automatic generation of the database based on hibernate xml.

Although I see a lot of stuff written about how many-to-many should be avoided. I don't see why. There are many cases when this is just the most logical assocation.

Kind regards.

Marc


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