Criteria c = getSession().createCriteria(Table1.class);
c.createAlias("table2", "table2", JoinFragment.LEFT_OUTER_JOIN);
c.add(Restrictions.disjunction().
add(Restrictions.ilike("fieldTab1", "blabla", MatchMode.ANYWHERE)).
add(Restrictions.ilike("table2.fieldTab2", "blabla", MatchMode.ANYWHERE));
this works for the mappings
<hibernate-mapping>
<class name="ro.test.Table1" table="TABLE1">
<id name="id" type="java.lang.Long">
<column name="TABLE1_ID"/>
<generator class="assigned"/>
</id>
<many-to-one name="table2"
class="ro.test.Table2">
<column name="TABLE2_ID"/>
</many-to-one>
<property name="fieldTable1" type="java.lang.String">
<column name="FIELD_TABLE_1" length="60"/>
</property>
</class>
<class name="ro.test.Table2" table="TABLE2">
<id name="id" type="java.lang.Long">
<column name="TABLE2_ID"/>
<generator class="assigned"/>
</id>
<property name="fieldTable2" type="java.lang.String">
<column name="FIELD_TABLE_2" length="60"/>
</property>
</class>
</hibernate-mapping>
You can put any condition you want but the table has to be linked in some way (in this example is one-to-many)
_________________ Alexandru BARBAT
|