[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3704) Criteria Query on property of sandwich-like @MappedSuperclass fails. HQL works

Kaspar Fischer (JIRA) noreply at atlassian.com
Tue Apr 7 07:47:37 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3704?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=32814#action_32814 ] 

Kaspar Fischer commented on HHH-3704:
-------------------------------------

Thanks, Vikash, for your quick response and sharing of your code.

Unfortunately, I realize that I am in a slightly different situation. I don't have property paths to entities but to components.
Something like this:

@Entity
class A {
  @Embedded
  B b;
}

@Embeddable
class B {
  String s;
}

and I want to list the rows in A sorted by "b.s". With aliases you can, it seems, not handle this case. - Or am I making a mistake at some stage?

(P.S. "Java Persistence with Hibernate" 2007 says: "Finally, note that at the time of writing only joining of associated entities or collections that contain references to entities (one-to-many and many-to-many) is supported in Hibernate with the Criteria API. The following example tries to join a collection of components: [...] Hibernate fails with an exception [...]")

> Criteria Query on property of sandwich-like @MappedSuperclass fails. HQL works
> ------------------------------------------------------------------------------
>
>                 Key: HHH-3704
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3704
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: query-criteria
>    Affects Versions: 3.3.1
>         Environment: hibernate 3.3.1, mysql 5.0.45
>            Reporter: Christian kalkhoff
>            Priority: Minor
>
> I have a hierarchy of @MappedSuperclasses, in my case:
> @MappedSuperclass class BaseEntity{...}
> @MappedSuperclass class NamedBaseEntity extends BaseEntity {...}
> @Entity class ConcreteEntity extends NamedBaseEntity {...}
> @Entity class AggregatingOtherEntity extends NamedBaseEntity {
>     ConcreteEntity concreteEntity;
> }
> BaseEntity holds property "id", NamedBaseEntity holds property "name". ConcreteEntity might have property "moonphase".
> If I create a Criteria search expression on AggregatingOtherEntity like
> eq("concreteEntity.id", 1L)
> that works.
> eq("concreteEntity.moonphase", "half decending") works either.
> BUT
> like("concreteEntity.name", "foobar")
> raises QueryException: 
> org.hibernate.QueryException: could not resolve property: concreteEntity.name of: AggregatingOtherEntity
> 	org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:67)
> 	org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:82)
> 	org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:54)
> 	org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1377)
> 	org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:457)
> 	org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:417)
> 	org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:68)
> 	org.hibernate.criterion.LogicalExpression.toSqlString(LogicalExpression.java:62)
> 	org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:357)
> 	org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:113)
> 	org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:82)
> 	org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:91)
> 	org.hibernate.impl.SessionImpl.list(SessionImpl.java:1577)
> 	org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
> 	[...]
> If I refactor the Criteria search to plain HQL (From AggregatingOtherEntity Where concreteEntity.name like 'half decending') it works. So there is a workaround.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       




More information about the hibernate-issues mailing list