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.  [ 6 posts ] 
Author Message
 Post subject: Mapping same table to 2 classes without discriminator
PostPosted: Wed Oct 20, 2004 7:07 am 
Newbie

Joined: Mon Oct 04, 2004 7:13 am
Posts: 19
I need to map the same table to 2 different classes where there is no discriminator. I've tried this

<class name="com.abc.Recoverer" table="RSASRECV" >
....


<class name="com.abc.FinancialAdjuster" table="RSASRECV">
.......


but it fails on the instanceAlreadyLoaded() method of Loader with WrongClassException.



I have been using the Jaxor O/R tool up until now and that lets me achieve the above.

Can I do the same in Hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 20, 2004 7:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
In HB2.x, you can't have two objects representing the same row associated with a session at the same time. I actually changed this in HB3, after thinking about it some more.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 20, 2004 7:21 am 
Newbie

Joined: Mon Oct 04, 2004 7:13 am
Posts: 19
OK, but what about the case of Lightweight versions of heavywiehgt classes?

In the reference manual it says:

"Explicit polymorphism is useful when two different classes are
mapped to the same table (this allows a "lightweight" class that contains a subset of the table columns)."


Are you saying that the above is not really achievable?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 20, 2004 7:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No of course not. Re-read what I wrote (difference between "object" and "class").


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 20, 2004 7:49 am 
Newbie

Joined: Mon Oct 04, 2004 7:13 am
Posts: 19
Thanks for your help. This is how I understand it:
If I attempt to load a lightweight object and a heavyweight object from the same table, that works fine UNLESS they both happen to point to the same row in that table in which case I'll get the WrongClassException.

Therefore I'm free to map Lightweight and Heavyweight classes to the same table but I run the risk of getting a WrongClassException at runtime.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 20, 2004 12:20 pm 
Regular
Regular

Joined: Tue Sep 28, 2004 6:34 pm
Posts: 50
Quote:
In HB2.x, you can't have two objects representing the same row associated with a session at the same time.


I guess you sort of can:)

I have managed to use Lightweight versions of heavywiehgt by using native query to get Lightweight.

My solution is:
1 I have defined
<class name="Lightweight " table="aTable">
</class>
<class name="Heavywiehgt " table="aTable">
</class>

2. use native sql query "select {co.*} from aTable" to get Lightweight

So far it works fine - but still this is workaround.

Does anyone have better idea?


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