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