-->
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.  [ 2 posts ] 
Author Message
 Post subject: criteria problem while or-restriction in multiple table
PostPosted: Mon Apr 13, 2009 7:15 am 
Newbie

Joined: Thu Nov 27, 2008 9:05 pm
Posts: 9
Hy folks

I'm using Criteria to build a simple filter.
In that filter I want to like-search if there's a value in any of the two fields (in different tables) im looking for.

I build the Criteria Query but it just come truth if the value is truth in every field.
I tried to use an or-restriction but I cant use it between different tables. (not pretty sure).

What can I do?
thankx


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 13, 2009 8:52 am 
Beginner
Beginner

Joined: Wed Oct 03, 2007 4:10 am
Posts: 46
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.