Further investigation showed that the problem occurs only when the two merge calls happen in separate transactions. See https://github.com/gregturn/spring-data-jpa-id-class-issues/pull/1