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

    How to set query condition on a nested property?

    Oleksandr Alesinskyy Newbie

      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.