In my current database we use logical deletions. This means that there could be many items with the same id, but we enforce that only one of them is active (i.e. the column is_active=Y) at any given time. However, the basic Session.get() doesn't look at any columns other than the given id column, so if I try to call get on an identifier that has several instances, it will fail since multiple rows will be found, even though only one of those rows has is_active=Y.
I am trying to use discriminators to get around this, but for some reason the query that is being generated is the same both with and without the discriminator. Here is the mapping file:
=====================================
<hibernate-mapping>
<class name="MyHost" table="HOSTS" discriminator-value="Y">
<id name="hostName" column="HOST_NAME">
<generator class="native"/>
</id>
<discriminator column="IS_ACTIVE" type="character"/>
</class>
</hibernate-mapping>
====================================
And here's how I call the get:
====================================
SessionFactory factory = new Configuration().configure().buildSessionFactory();
Session session = factory.getCurrentSession();
session.beginTransaction();
MyHost host = (MyHost)(session.get(MyHost.class, "my.test.host.com"));
=====================================
However, the query that Hibernate generates is:
=====================================
select myhost0_.HOST_NAME as HOST1_0_0_ from HOSTS myhost0_ where myhost0_.HOST_NAME=?
=====================================
As you can see, no mention of myhost0_.IS_ACTIVE. What am I doing wrong? Thanks in advance.
|