-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to handle delegation / composition with Hibernate?
PostPosted: Mon Apr 12, 2004 11:12 am 
Beginner
Beginner

Joined: Fri Feb 20, 2004 6:15 pm
Posts: 38
Hello,

Hibernate seems to work fine when you are following standard inheritance hierarchies, but I'm unable to get it working with delegation/composition style design.

I have interfaces A, B and B extends interface A:

A {

doA();

getID();

}

B extends A {

doB();

}

I then have AImpl and BImpl, but BImpl does not extend AImpl. BImpl instead uses composition/delegation and contains a field of type A.

So:

BImpl implements B {

A myA;

doA() {
myA.doA();
}

doB() {
1 + 1;
}

getID() {
myA.getID();
}

}


Now, the ID is in A, and when I write the mapper for BImpl I need to write a component element of A and have the ID property pulled from that. Hibernate doesn't seem to work here. If I declare the component of class="A" it gives a reflection error at runtime. If I declare the component of class="AImpl", first this is breaking the whole interface dependency, and second I get an error that the id property is not found.

So, how can I map the BImpl situation above? Is this a bug in hibernate?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 12, 2004 6:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
So, how can I map the BImpl situation above? Is this a bug in hibernate?

How would this be a bug, exactly?

Your domain model is sort of schizophrenic. At the interface level you describe it using an inheritence model, at the class level you instead try to say the association is rather a composition. So which is it?

Totally inferring from what I think you are trying to do, I would say that you really want a one-to-one relationship between A and B (they share the same key right?). Then if you want an interface over top of that which conceptually runs counter to the actual implementation, then just do it. When mapping things in hibernate, the way you conceptualize the associations at the class level is the way to map it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 13, 2004 9:56 am 
Beginner
Beginner

Joined: Fri Feb 20, 2004 6:15 pm
Posts: 38
steve wrote:
Quote:
So, how can I map the BImpl situation above? Is this a bug in hibernate?

How would this be a bug, exactly?

Your domain model is sort of schizophrenic. At the interface level you describe it using an inheritence model, at the class level you instead try to say the association is rather a composition. So which is it?

Totally inferring from what I think you are trying to do, I would say that you really want a one-to-one relationship between A and B (they share the same key right?). Then if you want an interface over top of that which conceptually runs counter to the actual implementation, then just do it. When mapping things in hibernate, the way you conceptualize the associations at the class level is the way to map it.


It seems that if I have the component mapping that says the key is in the B type, Hibernate should be able to successfully pull it out when it deals with an A type.

Is it safe to say that all concrete persistent classes must be known by Hibernate? I'm having a lot of trouble trying to program only to interfaces, but still use Hibernate.


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