The class BookPk is used with the annotation @EmbeddedId in the class Book, so it has to comply the constrains of a composite primary key. However, there are two things which are not complied:
- has protected no-arg constructor which should be public
- There isn't defined the hashCode() method
From the JPA 2.0 spec:
The following rules apply for composite primary keys:
• The primary key class must be public and must have a public no-arg constructor.
• The primary key class must define equals and hashCode methods. The semantics of value equality for these methods must be consistent with the database equality for the database types to which the key is mapped.