-->
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: bidirectional any
PostPosted: Thu Aug 09, 2007 12:10 am 
Beginner
Beginner

Joined: Wed Apr 18, 2007 1:44 pm
Posts: 27
Will hibernate ever support bidirectional any associations? I mean where the reference is made by a pair of kind-id instead of a normal fk, so that the target could be of different kind~class~entity~table (of course, fk constraints should not be generated here). I've tried a number of workarounds but they are far from ideal (custom queries, @where clauses, unidirectional any associations). I think this is a nice to have since associations to interfaces are pretty common and sometimes it's very difficult to map them to any of the hierarchy mappings that hibernate provides, because any class can implement an interface, not just a class that inherits from some common root. And although against database purisms it's a customary solution when the entity association needs to be flexible enough.

Cheers,
Carlos


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 12:25 am 
Beginner
Beginner

Joined: Wed Apr 18, 2007 1:44 pm
Posts: 27
Mh, just before anyone answers this, here is an obvious solution that doesn't work that good:

For a one-to-many bidirectional association:

1) at the source side use an any association

2) at each class at the target side (discriminated by kind) use a one-to-many association with a where clause to get the sources of the right kind

Well the problem is that each of the one-to-many associations generate a different fk constraint for the source side, and these constraints can't be fullfilled all at the same time because they don't take into account the kind field but just require that the source id field, when not null, references each of the target kinds simulateously.

Cheers,
Carlos


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.