0 Replies Latest reply on Mar 9, 2006 10:08 PM by Gus Gu

    Is it a bug on composite primary key

    Gus Gu Expert

      I ever posted a same question before. I use the composite primary key for my class

      @Entity
      @Table(name="group_members")
      @IdClass(MembershipPK.class)
      public class Membership implements Serializable {
      
       private long groupId;
       private long personId;
      
       public Membership() {}
      
       @Id
       @Column(name="GROUP_ID", nullable = false, insertable = false, updatable = false)
       public long getGroupId() {return groupId;}
       public void setGroupId(long groupId) {this.groupId = groupId;}
      
       @Id
       @Column(name="PERSON_ID")
       public long getPersonId() {return personId;}
       public void setPersonId(long personId) {this.personId = personId;}
      }
      
      @Embeddable
      public class MembershipPK implements Serializable{
      
       private long groupId;
       private long personId;
      
       public MembershipPK() {}
      
       public MembershipPK(long groupId, long personId) {
       this.groupId = groupId;
       this.personId = personId;
       }
      
       public long getGroupId() {return groupId;}
       public void setGroupId(long groupId) {this.groupId = groupId;}
      
       public long getPersonId() {return personId;}
       public void setPersonId(long personId) {this.personId = personId;}
      }

      When I tried the sql "select g from Membership g ", I always got an exception: Unknown column 'membership0_.personId' in 'field list'
      After I checked the log file, I found the transfered sql is:
      [org.hibernate.hql.ast.HqlSqlWalker] processQuery() :
      ( SELECT ( {select clause} (membership0_.personId, membership0_.groupId) ) ( FromClause{level=1} group_members membership0_ ) )

      It seems the system could not get the column PERSON_ID, which was annotated in class, and it always got the class attribute personId. I checked internet examples, and it seems there is no error in my codes. Can JBoss experts give an answer? Thank you in advance.

      GUS