-->
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: Criterai can't resolve property HSQL can
PostPosted: Wed Aug 03, 2005 6:02 am 
Newbie

Joined: Fri Feb 13, 2004 5:32 am
Posts: 3
Hi,
I'm trying to get a simple query working whith the Criteria API on Hibernate 3.0.5 but I just can't make it work.

MailBox 1----* Folder 1----- * Mail

The HSQL Query working is :
select count(mail) from mail where mail.folder.mailBox.id = '1'

But when I write the same request whith the Criteria API :

Criteria crit = session.createCriteria(Mail.class);
crit.add(Expression.eq("mail.folder.mailBox", "1"));
crit.setProjection(Projections.count("id").as("result"));
crit.list();

I've got an Exception

org.hibernate.QueryException: could not resolve property: folder.mailBox.id of: Mail
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:63)
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
at org.hibernate.persister.entity.BasicEntityPersister.toColumns(BasicEntityPersister.java:1086)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:403)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:369)
at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:42)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:314)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:81)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1303)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)

I just can't get it so if you have any idea.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 6:04 am 
Newbie

Joined: Fri Feb 13, 2004 5:32 am
Posts: 3
Sorry read
crit.add(Expression.eq("folder.mailBox", "1"));
instead of
crit.add(Expression.eq("mail.folder.mailBox", "1"));


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 6:43 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
ehsavoie wrote:
Sorry read
crit.add(Expression.eq("folder.mailBox", "1"));
instead of
crit.add(Expression.eq("mail.folder.mailBox", "1"));


Before this line, you need to create an Alias for folder.

crit.createAlias("folder","folder");

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 7:23 am 
Newbie

Joined: Fri Feb 13, 2004 5:32 am
Posts: 3
Thanks, it's working with

Criteria crit = session.createCriteria(Mail.class, "mail");
crit.createAlias("mail.folder", "folder");
crit.createAlias("folder.mailBox", "box");
crit.add(Expression.eq("box.id", id.toLong()));
crit.setProjection(Projections.count("id").as("result"));


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.