-->
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.  [ 1 post ] 
Author Message
 Post subject: Polymorphic Criteria Query Bug in 3.5.6?
PostPosted: Fri Oct 29, 2010 2:06 pm 
Beginner
Beginner

Joined: Sat Sep 24, 2005 11:04 pm
Posts: 21
Hibernate Version: 3.5.6

I came across this one earlier today... while it's definitely possible that I'm overlooking something obvious here, it seems that the current implementation of Criteria ignores (partially, at least) restrictions on properties that appear in multiple subclasses of a class hierarchy (mapped using a table per subclass strategy). For a simplified example to demonstrate the issue that I'm experiencing:

abstract class Vehicle { ... } -> tblVehicle
class Motorcycle { private String engineType ... } -> tblMotorcycle (1..1 Shared PK w/ tblVehicle)
class Car { private String engineType ... } -> tblCar (1..1 Shared PK w/ tblVehicle)
class Bicycle { ... } -> tblBicycle (1..1 Shared PK w/ tblVehicle)

If I create a Criteria query against class Vehicle with a Restriction of Restrictions.eq("engineType", "4 Cylinder") it seems to apply the where clause restriction to the first subclass containing the property in the hierarchy (ignoring additional subclasses that may contain the same property).

Generating SQL along the lines of:

select blah from tblVehicle this_
left outer join tblMotorcycle this_1_ on blah
left outer join tblCar this_2_ on blah
left outer join tblBicycle this_3_ on blah
where this_1_.EngineType = ?

where I would expect to see something closer to:

select blah from tblVehicle this_
left outer join tblMotorcycle this_1_ on blah
left outer join tblCar this_2_ on blah
left outer join tblBicycle this_3_ on blah
where (this_1_.EngineType = ? or this_2_.EngineType = ?)

I was able to resolve the issue using a SQL restriction, but thought I'd go ahead and throw this out there in the unlikely event that a blatant oversight isn't being made on my behalf.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.