1 Reply Latest reply on May 18, 2011 9:57 AM by al0

    How to set query condition on a nested property?

    al0

      I have  audited entities defined as below:

       

       

       

       

      {code}

      @Entity

      @Audited

      public class EndUserPo extends UserPo {

         ...

      }

      {code}

       

      {code}

      @Entity

      @Inheritance(strategy = InheritanceType.JOINED)

      @Audited

      public abstract class UserPo implements Comparable<UserPo> {

          @ManyToOne

          @JoinColumn(name = "B2BCUSTOMER_ID", nullable = false)

          @ForeignKey(name = "FK_USER_B2BCUSTOMER")

          private B2BCustomerPo b2BCustomer;

          ...

      }

      {code}

      {code}

      @Entity

      @Audited

      public class B2BCustomerPo implements Comparable<B2BCustomerPo> {

      ...

          @Column(unique = true, nullable = false)

          private String name;

      ...
      }

      {code}

       

      I need to write query finding a EndUser history based on a user's username and a name of the respective B2B customer.

      I tried following:

       

      {code}

      AuditReaderFactory.get(em).createQuery().forRevisionsOfEntity(clazz, false, true)

        .add(AuditEntity.property("username").eq("something"))

        .add(AuditEntity.property("b2BCustomer.name").eq("somethingElse")).getResultList();

      {code}

       

      Unfortunately is results in

      {quote}

      org.hibernate.QueryException: could not resolve property: b2BCustomer.name of: com.navteq.ncs.fbs.domain.persistence.EndUserPo_AUD [select e, r from com.navteq.ncs.fbs.domain.persistence.EndUserPo_AUD e, com.navteq.ncs.fbs.domain.persistence.FbsRevisionEntity r where e.username = :_p0 and e.b2BCustomer.name = :_p1 and e.originalId.REV.id = r.id order by e.originalId.REV.id asc]

          at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:81)

          at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:96)

          at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:62)

          at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1441)

          at org.hibernate.persister.entity.JoinedSubclassEntityPersister.toColumns(JoinedSubclassEntityPersister.java:696)

          at org.hibernate.hql.ast.tree.FromElementType.toColumns(FromElementType.java:357)

          at org.hibernate.hql.ast.tree.FromElementType.toColumns(FromElementType.java:326)

      {quote}

       

      Is there a way to address such nested property?

       

      Thanks in advance.

        • 1. Re: How to set query condition on a nested property?
          al0

          OK, I should read a documentation more carefully, it clearly states that it is impossible

          {quote}

          The main limitation of the current queries implementation is that you cannot traverse relations.

          You can only specify constraints on the ids of the related entities, and only on the "owning" side of the relation.

          This however will be changed in future releases.

          {quote}