Hibernate exception with @MapsId, @EmbeddedId

See this issue. It simply states that

org.hibernate.PropertyAccessException may be thrown if an Entity contains the following conditions:

  1. Uses @EmbeddedId
  2. Uses @JoinTable on a collection or association property/field, which references another property/field of the entity.

As you see, the only 'workaround' suggested so far is Do not use @EmbeddedId, which is kind of weird.


Solution Here: Got the same problem, and got it working now.

For it to work, the EmployeeId of your Employee class should be instantiated either in the constructor of Employee, or in the SessionBean before making the persistence.

Otherwise, it tries to populates the values of your embeddedid with it being null.

Not sure if this is normal or if it's a bad implementation of JPA specifications. I think the latter since the constructor for your PK is defined and hibernate should be able to call it by itself.