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>
QuestionIs 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