I can confirm this. I use following mapping:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="Site" table="sites" discriminator-value="not null">
<id name="siteID" unsaved-value="-1">
<column name="site_id" not-null="true" />
<generator class="native">
<param name="sequence">sites_site_id_seq</param>
</generator>
</id>
<discriminator column="status" />
<property name="name" />
<subclass name="ActiveSite" discriminator-value="1" />
</class>
</hibernate-mapping>
When I use query 'from ActiveSite', rows with discrminator set to value other than 1 are not returned. But session.load(ActiveSite.class, new Integer(1)) returns row even if discriminator is set to value other than 1. When I enabled logging with debug level, I can see that discriminator column is neither selected nor used in where. Hibernate uses following SQL query for this mapping when ActiveSite.class instance is requested via session.load method:
select activesite0_.site_id as site_id0_, activesite0_.name as name0_ from sites activesite0_ where activesite0_.site_id=?
I think, it should be something like this:
select activesite0_.site_id as site_id0_, activesite0_.name as name0_, activesite0_.status as status0_ from sites activesite0_ where activesite0_.status=1 and activesite0_.site_id=?
Tested on Hibernate 2.1.1.
|