-->
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.  [ 4 posts ] 
Author Message
 Post subject: One to many selection - Problem with simple select
PostPosted: Thu Sep 25, 2008 2:50 pm 
Newbie

Joined: Mon Jun 16, 2008 11:55 am
Posts: 2
Hello,

i have the following simple tables:

Table 1: NAME
Field1: NAME_ID
Field2: NAME

Table 2: NAME_ALIAS
Field1: ALIAS_ID
Field2: NAME_ID
Field3: ALIAS_NAME

So every NAME-object has a set of NAME_ALIAS objects.

I want to select all NAME objects that have a String like "123" in NAME.NAME OR NAME_ALIAS.ALIAS_NAME. I tried the following but it doesn´t work:

Criteria crit = getSession().createCriteria(Name.class);
crit.add(Restrictions.or(Restrictions.ilike("name", "%" + name + "%"),
Restrictions.ilike("nameAliases.aliasName", "%" + name + "%")));

Hope anyone can help me...

Thanks and best regards
Sysbeast


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 3:31 pm 
Beginner
Beginner

Joined: Wed Sep 24, 2008 5:44 pm
Posts: 34
Are you trying to do something like this? (scroll to bottom)

http://www.javalobby.org/articles/hibernatequery102/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 4:17 pm 
Newbie

Joined: Mon Jun 16, 2008 11:55 am
Posts: 2
thanks for you help... i tried somethink like this now:

createCriteria(Name.class)
.createAlias("nameAliases","alias")
.add(Expression.or(Expression.ilike("alias.alias", "%" + name + "%"), Expression.ilike("name", "%" + name + "%")))
.list();

But this criteria is only selecting me object swith the search string in the alias table but not in the name table.

I need all "Name" objects with the search string in "Name.name" OR "Name.nameAliases.alias" ...

Hope someone can realy help me... thanks and best regards
Sysbeast


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 4:56 pm 
Beginner
Beginner

Joined: Wed Sep 24, 2008 5:44 pm
Posts: 34
I tried the criteria you posted (on some of my objects) and it appears to do what you're asking of it. Maybe try looking at/posting the sql statement it generates.


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