embedded id mapping fails with descriptorexception there should be one non-read-only mapping for the primary key field in eclipselink

By putting @MapsId("clubId") on the association, you’re saying ‘clubId does not provide its own mapping. Instead, the mapping on this property here should be used to map the clubId property’.

This means that when persisting the entity, Eclipselink will use Team.club‘s id to populate the club_id join column, and then, it will use the value of that join column, to populate the Java property Team.embeddedId.clubId, whenever the entity is fetched/refreshed. Whatever mapping you put on Team.embeddedId.clubId will be ignored.

The error comes from the fact that Eclipselink does not consider club_id to be mapped twice. Instead, only the mapping on Team.club is taken into account. Being the only mapping for a primary key property, it may not be insertable = false, updatable = false.

The solution is simple:

  1. If you want Team.club to control the value of the club_id column, drop the insertable = false, updatable = false
  2. Conversely, if you want Team.embeddedId.clubId to control club_id, drop @MapsId altogether

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top