-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem using inheritance with discriminator
PostPosted: Mon Apr 10, 2006 12:48 pm 
Regular
Regular

Joined: Tue Mar 15, 2005 12:38 pm
Posts: 73
Location: Bucharest
Suppose you have a base class Person and two derived classes Customer and Employee. All objects are from the same table and inheritance is mapped through discriminators.

Now lets create a new class, say Document:

class Document
{
IList EmployeeList;
IList CustomerList;
}


(bare with me as this design is a MUST for me and my real situation is much more complicated and has to be programmed this way and I prefer not to map it in a single collection. My hierarchy has aprox 15 classes on the same table because the use case requires so).

If I do something like:
Session.CreateCriteria(typeof(Document))
.SetFetchMode("EmployeeList", FetchMode.Join)
.List();

At this point NH generates somthing like
"select ... from document inner join person on d.fk = p.id"

When the loader parses the results it will get at some point a row with the discriminator value corespondent to Customer (instead of Employee) and so it throw an WrongClassException as the discriminator in the row does not correspond to the given hierarchy.
The reason it throws this exception is that it does not generate a "where discriminator_col in (....)" in the select clause as it does when loading the collection lazy.

I also tried a workaround and mapped both lists like:
<bag name=...... where="discriminator_col = XXX">
..
</bag>

But, surprise, when fetched using join in criteria the generated sql does not contain the where expression that I set on the bag. When the bag is loaded separately the where condition is generated.

I think I should get this into JIRA but maybe someone knows what I've done wrong or knows a workaround.

Thanks,
Dragos

PS: if needed I can recreate the situation for a test case...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 7:17 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I don't think you did anything wrong, please submit a JIRA issue with a test case.


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