-->
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.  [ 3 posts ] 
Author Message
 Post subject: Mutli-level Criteria Projection
PostPosted: Thu May 05, 2005 4:22 pm 
Newbie

Joined: Thu May 05, 2005 3:45 pm
Posts: 1
Using Hibernate 3.0.2, I am trying to execute criteria queries using property projections that traverse the object graph something like this:

Code:
Criteria criteria = session.createCriteria(Root.class);
criteria.setProjection(Projections.property("propA.propB.propC"));
criteria.list();

where propA is a property of Root, propB is a property of propA, and propC is a property of propB.

It appears that Hibernate can handle projections out through "propA" without an alias, but I cannot get it to work for nested properties in an object graph. If your property path has several steps in it, this can mean a lot of alias creation.

It seems that the API relies on the use of aliases to make this kind of projection work, but that seems to me to be a lot of work to accomplish
something that seems pretty straight forward.

I have tried to create implementations of PropertyProjection that creates the alias tree itself, but then you need to make sure that the aliases are unique, otherwise you will get more errors. I do not have enough insight into the internals of Hibernate to know the best path to follow to make this solution work.

Ultimately, I would like to be able to create PropertyProjections using the full property path from the criteria root class, like you might do in HQL. This makes it easier to create these queries dynamically, which is part of the requirement for my current project.

So, I need to know if I am missing something about how to do this easily, if it cannot be done without creating a lot of aliases, or if Hibernate can be updated to make this work.

Thanks.

Hibernate version:3.0.2

Mapping documents:N/A

Code between sessionFactory.openSession() and session.close():
Criteria criteria = session.createCriteria(Root.class);
criteria.setProjection(Projections.property("propA.propB.propC"));
criteria.list();

Full stack trace of any exception that occurs:

org.hibernate.QueryException: could not resolve property: partA.partB.partC of: x.x.x.Root
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
at org.hibernate.persister.entity.BasicEntityPersister.toType(BasicEntityPersister.java:1094)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getType(CriteriaQueryTranslator.java:442)
at org.hibernate.criterion.PropertyProjection.getTypes(PropertyProjection.java:36)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(CriteriaQueryTranslator.java:297)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:81)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1236)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:299)

Name and version of the database you are using:N/A

The generated SQL (show_sql=true):N/A

Debug level Hibernate log excerpt:N/A


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 5:01 pm 
Newbie

Joined: Thu Nov 10, 2005 12:35 pm
Posts: 6
Did you ever find an answer?


Top
 Profile  
 
 Post subject: Re: Mutli-level Criteria Projection
PostPosted: Fri Sep 17, 2010 3:44 am 
Newbie

Joined: Tue Nov 25, 2008 11:24 pm
Posts: 1
Location: Ulaanbaatar, Mongolia
Have you found an answer?

_________________
Let's care our nature!


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