-->
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: qbc problem using objects within objects
PostPosted: Wed Mar 14, 2007 10:42 am 
Newbie

Joined: Wed Mar 14, 2007 10:16 am
Posts: 3
I'm using Hibernate 3.2, jdk 1.4, and spring 2.0

I was using HQL before for a query, but I want to change to use QBC instead. In HQL, the a portion of the query looks like this and it works fine:

String hql = "from FileCycleHistory fileCycleHistory "
+ " and UPPER(fileCycleHistory.feedFile.fileName) like '"
+ inFileName.toUpperCase()
+ "'";

I want to change this to QBC like this:

DetachedCriteria crit = DetachedCriteria.forClass(FileCycleHistory.class);

if (inFileName != null && inFileName.trim().length()!=0) {
inFileName = inFileName.replace('*','%');
crit.add(Restrictions.ilike("feedFile.fileName",inFileName));
}

However, I'm getting an error:
org.hibernate.QueryException: could not resolve property: feedFile.fileName of: com.fmrco.imt.fams.domain.FileCycleHistory

Queries where I just get a string within fileCycleHistory work fine, but this one needs to fetch a string within a FeedFile object in fileCycleHistory and it's giving me an error.

Any idea what's wrong here?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 11:17 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
For associations you have to create a subcriteria or an alias :
http://www.hibernate.org/hib_docs/v3/re ... sociations

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 1:03 pm 
Newbie

Joined: Wed Mar 14, 2007 10:16 am
Posts: 3
Thanks for the info. That has made one of my queries work, but the other one is a little more complex.

I have some code here:
DetachedCriteria crit = DetachedCriteria.forClass(FileDependency.class);

if (inFileName != null && inFileName.trim().length()!=0) {
inFileName = inFileName.replace('*','%');
crit.add(Restrictions.or(
crit.createCriteria("feedFile").add(Restrictions.ilike("fileName",inFileName)),
crit.createCriteria("dependsOnFile").add(Restrictions.ilike("fileName",inFileName))
)
);

Because I am using spring, I need to create a detached query and then call it via the hibernateTemplate.

How do I set an "or" condition using a detached query? Restrictions.or only works for arguments (Criteria, Criteria), but I have arguments (DetachedCriteria, DetachedCriteria) so the above code has an error.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 2:04 pm 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Maybe you can use createAlias instead of createCriteria and then use or(Restriction, Restriction) as it is shown in the doc

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


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.