-->
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.  [ 7 posts ] 
Author Message
 Post subject: use xref table for one-to-many association
PostPosted: Fri Jan 23, 2004 8:18 am 
Newbie

Joined: Fri Jan 23, 2004 8:09 am
Posts: 5
As I understand it, I cannot force Hibernate to use a xref table when modelling one-to-many relationships.

But this is something I would want to do by default.

If I have an entity, for example representing an Address, I want to relate that entity to many other entities (Client, Company, Branch, Department, Employee etc. etc.).

This means I keep having to add more and more foreign keys as the relationships are implemented. That's a pain for support, because ALTER TABLE has to be issued in the database.

Leaving aside arguments about the pros and cons of FKs versus xref, my point is I want to be able to choose, as I can in CMP (although I hate CMP for about 10 other reasons).

This is a barrier to adoption of Hibernate for us at the moment.

Can it be done (I hope I've missed something)? I could incorrectly model the relationship as many-to-many, but I don't want to do that.


Top
 Profile  
 
 Post subject: Can I use a xref table somehow for one-to-many association
PostPosted: Fri Jan 23, 2004 12:18 pm 
Newbie

Joined: Fri Jan 23, 2004 8:09 am
Posts: 5
Please, someone answer!

Can I do it?

This is a simple but important question for us.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It is not supported, you have to use many-to-many for this.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 12:23 pm 
Newbie

Joined: Fri Jan 23, 2004 8:09 am
Posts: 5
Do you have any plans to support it?

Although I'm not familiar with the codebase, it would seem not a radical rework to allow, and then the users can make the decision.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 12:26 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It was marked as "not easy" in all discussions we had about it. I also think that the relational SQL model is broken in that case. I don't think it is in the top ten of our priority list right now. Feel free to have a look at the source, we always welcome patches. We are very responsive to user requests, but this must be only the second time in 10 months someone asked for this feature.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 12:41 pm 
Newbie

Joined: Fri Jan 23, 2004 8:09 am
Posts: 5
Fair enough. I can live with that. We might look at it ourselves.

Our perspective comes from maintaining a large application over 10 years or more.

We find that extensive use of foreign keys can cause significant problems with delivery of new releases, and also make the application harder to change.

I don't agree that the relational model is necessarily broken when you use a x-ref for one-to-many. I think that's a rather bold statement :-)
Also, with regards to performance (which I know you weren't referring to) there are cases where an xref can be have significant advantages over foreign keys (and vice-versa of course).

All in all, it's a complex subject which I would prefer that users could decide.

But thanks for your responses. We'll probably start off using many-to-many and see how that pans out.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 12:54 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Well, you can of course ensure integrity with a unique constraint on the "one" key in the association table. I was thinking of a different issue, so forget that statement I made before.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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