-->
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.  [ 5 posts ] 
Author Message
 Post subject: polymorphic mapping of components within class
PostPosted: Wed Dec 03, 2003 2:57 am 
Newbie

Joined: Wed Dec 03, 2003 2:38 am
Posts: 1
Hi All,
Have a question regarding the mapping of class hierarchy. Let's say (hypothetically) that we have an Owner class that has a reference to a Vehicle interface. There are 3 implementation classes of Vehicle: Car, Truck and Wagon. All information is stored in one table: VehicleReg.
So we have the following hibernate mapping:

<class name="Owner" table="VehicleReg">
.....
<discriminator column="VehicleType"/>
<component name="vehicle"... ?
</class>

How do I tell Hibernate that it needs to create an implementation of Vehicle depending on the discriminator. And can we use a composite discriminator (i.e look at values not in one but in two columns)?
Any help would be greatly appreciated
best regards,
Evgueni


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 3:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Inheritance/polymorphism is not supported for components. You could try using a CompositeUserType, perhaps. Not sure if it would help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 3:51 am 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
That is, I think, the third person that's asked for this that I've seen since you told me no-one ever wants to do it.

So, if I wrote a patch to do it (assuming I'm capable of doing that) would you accept it?

I'm keen on it because I really do think it's the best way to map some of these structures.

If you did decide that you would accept it as a patch (or even if not), do you think it would be hard to do?

Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 3:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I would accept a patch that did not require changes to core code (or that required only very simple changes).

I think it could be done by implementing AbstractComponentType, or modifying ComponentType, together with very minor changes to the mapping metamodel.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 6:01 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Hi,

I am also interested on having polymorphic components so my questions are :
- Shorn, did you manage to create a patch for that ? If not, do you have any idea on how this could be achieved ?

Here is a case where this feature would help me.
I have a Client object. I have different levels of clients : NewClient, GoodClient, GoldClient. I want some polymorphism on my levels to be able to define different behaviour on different client level. I also don't want to create a new Client object when the level of my client change.
Thus I have this classes :
Code:
public class Client
{
  public Level myLevel;
}
public abstract class Level
public class LevelNew extends Level
public class LevelGood extends Level
public class LevelGold extends Level


As clients and levels are thightly coupled, I want to save them on the same db table. So, as far as I know, I have to make the level a component of the client class. This leads to the need of a subcomponent.

I present you this example because maybe I missed something in hibernate and it is possible to have all this classes mapped on one table. But if no, subcomponents seems to be a really useful feature

Seb


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