-->
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: Criteria queries and projection of component properties
PostPosted: Mon May 21, 2007 7:25 am 
Newbie

Joined: Mon May 21, 2007 3:36 am
Posts: 16
Hi!

I've tried to use hibernate's criteria query API to execute a query that defines a projection using a component property.
The query's root entity is 'Person'. The property used for projection is 'name' of (component) type 'Name'.
Unfortunately, that does not work - instead, the following exception is thrown:

org.hibernate.QueryException: property does not map to a single column: name

Hibernate version:

3.2.3.ga (JBoss 4.2.0.GA)

Code between sessionFactory.openSession() and session.close():

(Note: Class Person has a property 'name' of type 'Name'. The property 'name' is mapped as component using the @embedded annotation on the method 'public Name getName()'.)

Code:
Example examplePerson = Example.create(person);
examplePerson.ignoreCase().enableLike();

Criteria criteria =  session.createCriteria(Person.class);
criteria.add(examplePerson);
criteria.setProjection(Projections.property("name"));

@SuppressWarnings("unchecked")
List<Name> result = criteria.list();


Full stack trace of any exception that occurs:

org.hibernate.QueryException: property does not map to a single column: name
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumn(CriteriaQueryTranslator.java:371)
at org.hibernate.criterion.PropertyProjection.toSqlString(PropertyProjection.java:41)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getSelect(CriteriaQueryTranslator.java:310)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:71)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.dgr.profi.server.offert.HibernateQueryService.findPerson(HibernateQueryService.java:59)

Name and version of the database you are using:

MySQL 5.0.19-nt


Top
 Profile  
 
 Post subject: Bug in projection mechanism of criteria-api?
PostPosted: Thu May 24, 2007 7:17 am 
Newbie

Joined: Mon May 21, 2007 3:36 am
Posts: 16
OK, it seems there is no proper solution to this problem. So this might be a bug.

In the meantime I've found two possible workarounds to this problem:

  1. Do not use projection but query the entire entity. Then the composite property can be accessed programmatically.
    Of course this means that the entire entity is retrieved instead of just the properties I'd like to have.
  2. Use a projection list containing every single property of the required component property. An
    Code:
    AliasToBeanResultTransformer
    can be used to transform the discrete properties to a single component bean.
    This solution is fine as long as the result should contain the component property only - as soon as other properties are required too, it does not work any more.


Or is there any mechanism I've not found yet?


Top
 Profile  
 
 Post subject: Same problem
PostPosted: Wed Mar 19, 2008 5:20 am 
Newbie

Joined: Tue Mar 08, 2005 4:57 am
Posts: 8
Hi,

Using hibernate 3.2.5 GA

I'm having the same problem, I cannot access components through in projections. I think it may have something to do with aliases not being propogated for components.

I tried adding the line:

criteria.createAlias("foo.baz", "baz");

where foo is my class and baz is my component

and then in the projection I have

projectionList.add(Projections.property("baz.bar").as("bar"));

When I execute the query with this amendment, I get 'could not resolve property bar of foo! Without the alias, if I just have foo.baz.bar in my projection, I get the error message, could not find property foo.bar.baz.

Any pointers, hints? or is this something that should be reported as a bug?

Cheers


Top
 Profile  
 
 Post subject: Same problem
PostPosted: Wed Mar 19, 2008 5:21 am 
Newbie

Joined: Tue Mar 08, 2005 4:57 am
Posts: 8
Sorry, double post. Deleted


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.