-->
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.  [ 1 post ] 
Author Message
 Post subject: Inheritance query on parent class and child classes using or
PostPosted: Tue Aug 31, 2004 7:11 pm 
Newbie

Joined: Tue Aug 31, 2004 6:37 pm
Posts: 1
Hibernate version:

2.1.6

Mapping documents:

Code:
<hibernate-mapping package="com.xxx.domain.model.pojo">
   <class name="User" table="`USER`">
      <id
         column="USER_ID"
         name="Id"
         type="java.lang.Long"
      >
         <generator class="vm" />
      </id>
      <property
         column="DISABLED"
         length="10"
         name="Disabled"
         not-null="true"
         type="integer"
       />
      <property
         column="PASSWORD_HASH"
         length="50"
         name="PasswordHash"
         not-null="true"
         type="string"
       />
      <property
         column="PRIMARY_EMAIL"
         length="20"
         name="PrimaryEmail"
         not-null="false"
         type="string"
       />
      <property
         column="DISABLE_REASON"
         length="50"
         name="DisableReason"
         not-null="false"
         type="string"
       />
      <property
         column="USER_NAME"
         length="16"
         name="UserName"
         not-null="true"
         type="string"
       />

      <many-to-one
         class="User"
         name="ParentUser"
         not-null="true"
      >
         <column name="PARENT_USER_ID" />
      </many-to-one>
      <many-to-one
         class="UserType"
         name="UserType"
         not-null="true"
      >
         <column name="USER_TYPE_ID" />
      </many-to-one>
      <joined-subclass name="Client" table="CLIENT">
         <key column="USER_ID" />
         
         <many-to-one
            class="ClientType"
            name="ClientType"
            not-null="true"
         >
            <column name="CLIENT_TYPE_ID" />
         </many-to-one>
         
         <many-to-one
            class="ClientAccountState"
            name="AccountState"
            not-null="true"
         >
            <column name="ACCOUNT_STATE_ID" />
         </many-to-one>
         
         <joined-subclass name="Company" table="COMPANY">
            <key column="USER_ID" />

            <property
               column="COMPANY_NAME"
               length="32"
               name="CompanyName"
               not-null="true"
               type="string"
             />
            <property
               column="COMPANY_NUMBER"
               length="20"
               name="CompanyNumber"
               not-null="true"
               type="string"
             />
            <property
               column="TAX_REG_NUMBER"
               length="30"
               name="TaxRegNumber"
               not-null="false"
               type="string"
             />            
         </joined-subclass>
         <!--
            <joined-subclass name="Individual" table="INDIVIDUAL">
            <key column="USER_ID"/>
            
            <many-to-one
            name="IndividualTitleType"
            class
         //-->
      </joined-subclass>
   </class>
</hibernate-mapping>


Question

Is it posible to write a query in hibernate to search on properties of the parent class and the

child classes using "or" (disjunction)

The effect that I am looking for in normal sql would be:

Code:
select
  u.* ,
  c.*,
  cy.*
from 'USER' u
  left outer join client c on (u.user_id = c.user_id)
  left outer join company cy on (u.user_id = cy.user_id)
  ....posible more joins to child tables ...
where
  (u.user_name like :searchtext)
    or (c.primary_emial = :searchtext)
    or (cy.company_name = :searchtext)
  ...posible more or statements.....


Hibernate using the criteria API or a Query object will then return a list of objects that can
be tested with instanceof to see wat type of object it is

I have tried using a query object:

Code:
   
Query q = session.createQuery("from User as user where  ((user.UserName like :SearchText)    or (user.CompanyName like :SearchText))");

    q.setString("SearchText",ASearchText);


but obviously hibernate thinks that I am only interested in user objects and not the complete inheritance tree.

I also played around with the criteria API but could not find a way of doing it


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

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.