2 Replies Latest reply on Aug 11, 2005 4:43 AM by epbernard

    problem with composite key: "ids for this class must be manu

    khalidhajsaleh

      I am getting the error: ids for this class must be manually assigned before calling save" when i try to save a class with a composite pk.

      It is obvious that the container is expecting to set the my pk before saving. Here is the problem: The composite key contains two fields. I wanted to generate one of the fields myself but let the system generate the other field in the key. Here is my code


      my pk:

      @Embeddable(access = AccessType.FIELD)
      public class CategoryPK implements Serializable {
      
       private int id;
       private String type;
      
       //this is the key I wanted auto generate
       public int getId() {
       return id;
       }
      
       //this is the key I wanted the user to input
       public String getType() {
       return type;
      
      public boolean equals(Object obj){\\some code}
       public int hashCode() {\\some code}
      
       }
      }


      My class


      @Entity
      @Table(name = "Catgory")
      public class Category implements Serializable {

      private CategoryPK categoryPK;
      private String description;

      // my pk
      @Id(generate = GeneratorType.NONE)
      public CategoryPK getCategoryPK() {
      return categoryPK;
      }
      }

      Any suggestions?