-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Using LIKE expression for discriminating subclasses
PostPosted: Wed Oct 26, 2005 8:30 pm 
Newbie

Joined: Wed Oct 26, 2005 4:57 pm
Posts: 5
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]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 6:35 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://opensource2.atlassian.com/projec ... se/HHH-948


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 11:55 am 
Newbie

Joined: Wed Oct 26, 2005 4:57 pm
Posts: 5
i added a comment in the relevant issue on JIRA


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.