1 Reply Latest reply on Jan 26, 2006 10:50 PM by David Webster

    EJB-QL query on partial part of a compound key

    David Webster Newbie

      I cannot seem to get the syntax down here. I have a compound primary defined something like this:

      @Entity
      @Table(name = "Person")
      public class Person implements Serializable {
      PersonPk pk;
      .
      .
      .

      @EmbeddedId({
      @AttributeOverride(name=?ssn?),
      @AttributeOverride(name=?tshirtsize?)})
      public PersonPK getPk()
      { return pk; }




      @Embeddable
      public class PersonPK implements Serializable
      {
      private String ssn;
      private String tshirtsize;
      ...
      }

      But when I go to do a query on the leading field of the compound key, in this case to get all the tshirtsizes associated with a specific ssn in a query like:

      public @Stateless class PersonEJBBean implements PersonEJB
      {

      @PersistenceContext (unitName = "Personnel")
      protected EntityManager vEm;

      List getTshirtsizeBySsn (long ssn) {

      List ssnList = Em.createQuery("from Person p where p.ssn = :Ssn)
      .setParameter("Ssn", new Long(ssn))
      .getResultList();

      .
      .
      .
      I get an InvocationException the states:
      could not resolve property: ssn of Person [from Person p where ......]

      ?????

      I've tried everything I can think of to execute a query on the leading part of a compound key, but cannot seem to come up with an acceptable syntax.

      Any ideas?