Page 1 of 1

About Question enthuware.oce-jpad.v6.2.572 :

Posted: Tue Mar 21, 2017 11:15 am
by unvector
I am wondering whether primary key class does really need to be Serializable - spec. of JPA 2.0 says that:
The primary key class must be serializable.
(...)
The primary key class must define equals and hashCode methods.
But later in the same chapter we can see examples in section 2.4.1.3:

Code: Select all

public class DependentId {
    String name; // matches name of @Id attribute
    long emp; // matches name of @Id attribute and type of Employee PK
}

Code: Select all

@Embeddable
public class DependentId {
    String name;
    long empPK; // corresponds to PK type of Employee 
}
There is no "implements Serializable" as well as no hashCode() nor equals() methods. Are these examples make some assumptions about what is obvious to implement? Or they are complete?

Re: About Question enthuware.oce-jpad.v6.2.572 :

Posted: Tue Mar 21, 2017 10:53 pm
by admin
It could be an oversight on their part. Ideally, they should have specified "implements Serializable" in their code.

-Paul.