我对休眠条件查询有疑问。我有:
DetachedCriteria carCriteria = DetachedCriteria.forClass(Car.class);
List<Car> cars = getHibernateTemplate().findByCriteria(carCriteria);
for(Car car : cars) {
System.out.println("class type " + car.getClass());
}
上面打印了类类型 model.FourByFour,其中 FourByFour 扩展了 Car。因为我在 DetachedCriteria 中指定了 Car 类,所以我期望类类型是 Car 而不是 FourByFour。
映射(简化):
<hibernate-mapping default-access="field" default-lazy="true" package="model">
<class name="model.Vehicle" table="VEHICLE">
<id column="VEHICLE_ID" name="id" type="long">
<generator class="native" />
</id>
...
<joined-subclass extends="model.Vehicle" name="model.Car" table="CAR">
<key column="VEHICLE_ID" />
....
<joined-subclass extends="model.Car" name="model.FourByFour" table="FOUR_BY_FOUR">
<key column="VEHICLE_ID" />
</joined-subclass>
</joined-subclass>
</class>
如何使从条件查询返回的对象成为 Car 对象而不是 FourByFour 对象?