Community
Participate
Working Groups
Build Identifier: I-3.4.0-20111117042436 Create an entity like the one below and corresponding ID class. @IdClass(TestPK.class) @Access(AccessType.PROPERTY) public class Test implements Serializable { @Transient private int id_1; private int id_2; private static final long serialVersionUID = 1L; public Test() { super(); } @Id public int getId_1() { return this.id_1; } public void setId_1(int id_1) { this.id_1 = id_1; } @Id public int getId_2() { return this.id_2; } public void setId_2(int id_2) { this.id_2 = id_2; } } A sample project is attached. An error message is given complaining "The attribute matching the ID class attribute id_1 is not mapped as a primary key."; however, the corresponding attribute id_1 of the entity is indeed mapped as primary key on the property. The problem is we try to count all the mapped attributes, the properties and annotated fields in this case (entity has property access type), including transient ones for the entity. It ends up with two attributes same name matching the corresponding ID attribute and one of them is annotated as transient so when doing the validation we try to go through each of them to check whether the matching ones are annotated as primary key and give the error message when finding the transient one is not. Reproducible: Always
Created attachment 207630 [details] sample project
I can also get this invalid error with this use case: @Entity @IdClass(DependentId.class) @Access(AccessType.FIELD) public class Dependent { @Transient String name; @Id @ManyToOne Employee emp; @Id @Access(AccessType.PROPERTY) public String getName() { return name; } public void setName(String name) { this.name = name; } } This might be a more valid use case, the one Nan gave has @Transient defined on the id_1 field when it's not necessary to define it. I'm bumping this to major since it results in invalid validation
Created attachment 209857 [details] Proposed Patch
Patch committed to maintenance and head for M5.
.
I get the same error for the following relatively simple case: Entity: @IdClass(CompositeId.class) @Entity @Cacheable(false) public class Album extends ContentItem implements Serializable { private static final long serialVersionUID = 1L; @Id private String title; @Id private String ancestor; private String album; } Id: public class Composite implements Serializable { private static final long serialVersionUID = 1L; private String title; private String ancestor; } The error is: "The attribute matching the ID class attribute title is not mapped as a primary key" What is strange to me is the fact that if I define the Id class in the same file as the Entity everything is just fine. Unfortunately that is not a possible workaround since the id class can't be used outside the package and I can't write my unit tests.
(In reply to comment #6) As a workaround, you could disable this error message in the JPA preferences at the workspace or project level. Currently this fix is only in the Juno release.