2 Replies Latest reply on Jan 6, 2005 6:00 AM by Rudie Ekkelenkamp

    Howto use order by query on composite primary key fields?

    Rudie Ekkelenkamp Newbie

      Hi,

      I would like to know how I can use an order by clause on the composite primary key part of an entity EJB.
      If I use an order by on a non-composite primary key field, it works just fine.

      I tried the following.

      My UserEJB entity bean has a composite primary key:

      /**
      * Return the composite primary key.
      *
      * @return com.finalist.entity.tuser.UserPK with the primary key.
      */
      @Id(generate = GeneratorType.NONE)
      @Dependent({
      @DependentAttribute(name = "UserId", column = {@Column(name = "USER_ID")} )
      ,@DependentAttribute(name = "Name", column = {@Column(name = "NAME")} )
      })
      public com.finalist.entity.tuser.UserPK getPrimaryKey() {
      return primaryKey;
      }

      I would like to use a query where i can use a order by on the primary key fields. I tried the following queries:

      from com.finalist.entity.tuser.UserEJB e order by e.primaryKey.userId, e.primaryKey.name
      from com.finalist.entity.tuser.UserEJB e order by e.userId, e.name

      It will result in the following exception:

      org.hibernate.QueryException: could not resolve property: primaryKey.userId of: com.finalist.entity.tuser.UserEJB [from com.finalist.entity.tuser.UserEJB e order by e.primaryKey.userId, e.primaryKey.name]

      Hope you can help.

      Rudie Ekkelenkamp.