Search code examples
javajdo

JDO no fields have been identified as primary key fields


I recently began to see JDO errors such as

Class X has been specified with an object-id class javax.jdo.identity.StringIdentity yet no fields have been identified as primary key fields.

My classes were using javax.persistence.Id annotations such as:

@Id
final private String key;

Solution

  • It turns out that this is due to marking key fields as final. To fix, it was simply necessary to change the declaration to something like the following:

    @Id
    private String key;
    

    Leaving this here for the benefit of posterity!