-->
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.  [ 4 posts ] 
Author Message
 Post subject: using discriminator with joined-subclass
PostPosted: Tue Feb 17, 2004 3:15 pm 
Newbie

Joined: Tue Feb 17, 2004 3:09 pm
Posts: 2
Is there anyway to use a discriminator with a joined subclass? In our situation, we have a poorly designed legacy schema, where each flavor of our base domain object has it's unique properties in their own table. For example, we have a Automobile table and then a Car and Truck table. The Automobile table holds the common properties, and the Car and Truck tables hole the properties unique to cars and trucks.

Ideally, I'd like to be able to ask hibernate for an automobile by primary key, and it will return the corresponding car or truck object. I can put a type code on in the Automobile table to assist it, but major changes to the schema can't be made for legacy reasons.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 3:23 pm 
Beginner
Beginner

Joined: Tue Jan 27, 2004 2:14 pm
Posts: 40
Location: Atlanta, GA, USA
Why do you need to use a discriminator? It seems like just using a <joined-subclass> will solve your problem. Check out chaper 16.1 in the docs.

Code:
<class name="Automobile table="AUTOMOBILE">
<id name="id" type="long" column="AUTO_ID">
<generator class="native"/>
</id>
...
<joined-subclass name="Car" table="CAR">
<key column="AUTO_ID"/>
...
</subclass>
<joined-subclass name="Truck" table="TRUCK">
<key column="AUTO_ID"/>
...
</subclass>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 3:31 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
and
Code:
session.load(Automobile.class, myId);

will do the job

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 3:49 pm 
Newbie

Joined: Tue Feb 17, 2004 3:09 pm
Posts: 2
Well what do you know, no need for the discriminator. I'm not sure why I thought I needed it. We've had the if/then statement from hell to deal with this.[/code]


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