Hi,
I started using hibernate this week,
I have downloaded the latest version and i'm using Oracle 10g.
What i tried to do is a multiple inheritance using a single table with a discriminator column.
After reading the code i realized that when selecting records of a Class all its subclasses are retreived by using their discriminator values within a single IN expression .
This really slowed my test application down,
why not use a LIKE expression ?
I added a little code to the
RootClass,
HbmBinder and the
SingleTableEntityPersister Classes that will consider a new attribute named 'pattern' for the discriminator Element.
Then if it is set to true a LIKE expression is used instead of the IN expression.
for example :
if i had wanted that my discriminator column's name would be 'type'
and i have an Emp Class which has 'emp' in the TYPE.
The first subclass - Killer will have 'emp.killer'
The second (subclass of Emp) - Proffesor will have 'emp.proffesor'
The Third (subclass of Killer) - RetiredKiller will have 'emp.killer.retired'
let say the mapping will look like this :
Code:
<class name="Emp" table="emp">
<id name="id" column="id">
<generator class="sequence">
<param name="sequence">emp_seq</param>
</generator>
</id>
<discriminator column="type" type="string" pattern="true"/>
<property name="name"/>
<subclass name="Killer" discriminator-value="emp.killer">
<property name="weapon" />
<subclass name="Killer" discriminator-value="emp.killer.retired">
<property name="years_from_retirment" />
</subclass>
</subclass>
<subclass name="Proffesor" discriminator-value="emp.proffesor">
<property name="weapon" />
</subclass>
</class>
Then loading my Emp class will create the following SQL
SELECT name FROM emp WHERE type LIKE 'emp%'
anyone else encountered this need ?
(Forthermore the IN SQL expression as a limit on how many values could be inside of it .
The InFragment Class doesn't take it into consideration which can cause an unneccery SQLException).
- shmeff.
[/code]