-->
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: modelling interface inheritance in hibernate
PostPosted: Thu Dec 18, 2003 7:04 am 
Newbie

Joined: Tue Sep 02, 2003 11:03 am
Posts: 3
Hibernate is excelent in modelling implementation inheritance, where class A extends class B.

Suppose now that for some reason (e.g., following some advice in the GoF book) we model domain objects using interface inheritance, so that our idiomatic java code would be as follows:

interface A {
//...
}

interface B extends A {
//...
}

class AImpl implements A {
//...
}

class BImpl implements B {
private A a;
//wrapper methods for interface A
//...
}

This can be modelled in hibernate, e.g., using two distinct classes, and a many-to-one unique relationship from B to A:

<class name="AImpl"
proxy="A"
table="a">
<!-- -->
</class>

<class name="BImpl"
proxy="B"
table="b">
<!-- -->
<many-to-one name="a" column="a_id" class="AImpl" unique="true"
not-null="true"/>
</class>

When doing a polymorphic query, session.find("from A") we then get all A instances in the datastore, plus all B instances in the datastore; we therefore get twice all B instances.

I therefore guess that I am wrong and that the above is not the right way to implement interface inheritance in hibernate. I would greatly appreciate if anybody knew the correct way for interface inheritance to work with polymorphic queries without getting duplicate instances?


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.