Hibernate version: 3.2.5GA
Database: Oracle 10g / DB2 v8
Mapping documents:
Code:
<hibernate-mapping>
<class name="com.qxlva.Person" table="PERSON" dynamic-update="true" dynamic-insert="true" lazy="true">
<id name="pid" column="PERSON_PID" type="long" unsaved-value="null">
<generator class="seqhilo" />
</id>
<discriminator column="PERSON_TYPE" length="50" type="string"/>
<property name="familyName" column="FAMILY_NAME" type="string"/>
<subclass name="com.qxlva.PersonOne" discriminator-value="PERSON_ONE" />
<subclass name="com.qxlva.PersonTwo" discriminator-value="PERSON_TWO" />
</class>
</hibernate-mapping>
I've attempted to look for anyone else that's hit this problem, but have hit a blank.
Our application makes heavy use of mappings with subclasses identified with discriminators. We're finding that due to the way the SQL queries are generated by Hibernate, it's leading to a lot of hard parses of the queries in the database, which is subsequently impacting on performance.
For example, the above mapping would generate the following SQL, when loading by identifier, using the following code:
Code:
session.load(PersonOne.class, identifier);
Quote:
select personone0_.PERSON_PID as PERSON1_1_0_, personone0_.FAMILY_NAME as FAMILY3_1_0_ from PERSON personone0_ where personone0_.PERSON_PID=? and personone0_.PERSON_TYPE='PERSON_ONE'
The majority of our hard parses are being caused by the discriminator section of the query having a hard-coded where-clause value, so my simple question is this: is there any way to configure Hibernate to use bind variables for setting the discriminator value? I'm aware that we can set the discriminator values via bind variable for HQL queries, so these don't concern me. The queries which do concern me are those which retrieve via identifier, usually when pulling out lazy-loaded associations, as I don't have direct control over them (or at least I don't think I do!).
I've spent most of the day immersed in the Hibernate source code and my guess is that there isn't a way to configure this, but before I start on the lengthy task of potentially adding this functionality in, I thought it would be better to check.
Code: