I know the following 2 ways to declare a composite Primary key:
********* Solution 1 *********
@Entity @IdClass(CompositePK.class) public class A { @Id private long uid; @Id private String zone; } public class CompositePK { private long uid; private String zone; }
********* Solution 2 *********
@Entity public class A { @EmbeddedId private CompositePK pk; } @Embeddable public class CompositePK { private long uid; private String zone; }
In both solutions I expected I could get a generated value for the field uid by simply adding the documented annotation @GeneratedValue like the following:
Solution 1) class A { @Id @GeneratedValue private long uid; ... }
Solution 2) class CompositePK { @GeneratedValue private long uid; ... }
Actually I have several Entity classes (A, B, C, D, etc.) using the same CompositePK, so I'd prefer Solution 2 to have a more compact coding. But unfortunately the only working one is Solution 1.
Is this an issue or simply a not contemplated future?