2 Replies Latest reply on Jan 7, 2008 10:11 AM by memema

    EmbeddedId and GeneratedValue

    jc7442

      I'd like to use an embeddedID for some of my classes. Th class PK is an embeddable, it contains one field:

      private long id;


      I'd like to generate the value, I've try:
      @Id
       @GeneratedValue(strategy = GenerationType.TABLE)
       @Column(name="CUST_ID")
       private long id;


      In that case annotaions are not used (PK is not generated).

      Any idea how to have a generatedValue for a PK in a embeddedID ?

      PS: I'd like to use an embedded ID for typing the PK. I do not like to see long everywhere in the application. It may be bug prone.

        • 1. Re: EmbeddedId and GeneratedValue
          jc7442

          Ive try the same kinds of think with IdClass:

          @Entity
          @Table(name = "WAREHOUSE")
          @IdClass(WarehousePK.class)
          public class Warehouse {
           long name;
          
           String city;
          
           @Id
           @GeneratedValue(strategy = GenerationType.TABLE)
           @Column(name = "W_NAME")
           public long getName() {
           return name;
           }
          ...
          }


          GeneratedValue annotation is ignored.

          Any idea on how to have a typed PK with a generated value ?

          • 2. Re: EmbeddedId and GeneratedValue
            memema

            I have the same question? Some idea? Thanks