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.
|