-->
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.  [ 7 posts ] 
Author Message
 Post subject: joined-subclass collections
PostPosted: Mon Apr 12, 2004 3:21 pm 
Newbie

Joined: Mon Mar 08, 2004 2:24 pm
Posts: 13
Location: Tampa, FL, USA
I have a class Decision that has a one-to-many relationship with another object, DecisionParty. Each of these objects map to their own table. The persisting of these objects is working fine.

I then created DecisionPartyA and DecisionPartyS, both subclasses of DecisionParty. Because both of these classes also have their own table, I've mapped them as joined-subclasses (of DecisionParty).

Each Decision that gets instantiated will have a collection of either DecisionPartyA or DecisionPartyS, but I won't know that until runtime. The problem is that one-to-many mapping in Decision has to refer to some class. Currently, I've got DecisionParty listed as that class, but when I run the app, I keep getting ClassCastExceptions becauses it's actually the subclasses that eventually get instantiated.

What is the preferred way to handle this type of situation?

Thanks,
John


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 13, 2004 1:59 am 
Regular
Regular

Joined: Mon Oct 20, 2003 3:14 am
Posts: 53
Location: Sterling, VA, USA
If a DecisionPartyX is a subclass of DecisionParty, you shouldn't be getting a ClassCastException by referring to a DecisionPartyX as a DecisionParty. The other way around would definitely be a problem, but what you say you are doing sounds okay.

Makes me think what youre actually doing isn't what you think it is :-)

Can you post the relevant code/xml/exception (and where point out the line where the exception is occuring?).

_________________
"A statistician is a mathmetician, broken down by age and sex".


Top
 Profile  
 
 Post subject: discriminators with joined-subclasses??
PostPosted: Tue Apr 13, 2004 11:52 am 
Newbie

Joined: Mon Mar 08, 2004 2:24 pm
Posts: 13
Location: Tampa, FL, USA
Sorry, looks like I mistyped the last part of the scenario. I'll try again...

When a Decision gets instantiated, it is a collection of DecisionParty objects that get instantiated --it is the DecisionParty class that is referenced in the one-to-many mapping of Decision.

What I want is a collection of the appropriate subclass to be instantiated, but which subclass depends on which Decision gets instantiated. I guess the behavior I want would be similar to <subclass> where a discriminator could be used, but because the DecisionParty and DecisionPartyX have their own tables, I'm using <joined-subclass>.

Can I use discriminators with joined-subclasses??? If so, is the mapping notation the same? Would data be saved to both tables when saving the subclass?

Hope this is clearer

P.S. - The ClassCastException is occuring when I pull items out of this collection and try to cast them as the specific subclass.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 13, 2004 12:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is not possible in 2.1. It is possible in Hibernate3 CVS. (Actually, the way you do it is use ordinary <subclass> mapping, together with <join>s.)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 13, 2004 12:11 pm 
Newbie

Joined: Mon Mar 08, 2004 2:24 pm
Posts: 13
Location: Tampa, FL, USA
Wow.. that was fast. Thanks Gavin. Can you point me to some sample mappings that would be similar to what I'd want? I'm reviewing the doc now, but specifics would be great.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 13, 2004 11:48 pm 
Regular
Regular

Joined: Mon Oct 20, 2003 3:14 am
Posts: 53
Location: Sterling, VA, USA
gavin wrote:
This is not possible in 2.1. It is possible in Hibernate3 CVS. (Actually, the way you do it is use ordinary <subclass> mapping, together with <join>s.)


I think I was trying something similar and XDoclet wouldn't let me.

I have a joined-subclass I want to further subclass with a discriminator.

Not possible?

http://forum.hibernate.org/viewtopic.php?t=929863&highlight=

_________________
"A statistician is a mathmetician, broken down by age and sex".


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 14, 2004 2:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
As I said, it is not possible in 2.1


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