Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy JPA-2.0 Primary Key Classes have to implement Serializable but my example works without?
    primarykey
    data
    text
    <p>In many sources I have read PrimaryKey Classes and even JPA2 entities should be serializable.</p> <p>IN my example (legacy database) there is a relationship between employee and languages:</p> <p>Employee Class:</p> <pre><code>@Entity @IdClass(EmpleadoId.class) @Table(name = "NO_INFGRAEMPL") public class Empleado { @Id @Column(name = "IGECOMPANIA", unique = true) private String compania; @Id @Column(name = "IGENUMEROIDENTIFIC", unique = true) private String numeroIdentificacion; //... } </code></pre> <p>Employee Compound PrimaryKey Class:</p> <pre><code>public class EmpleadoId { private String compania; private String numeroIdentificacion; //... } </code></pre> <p>Employee Language SKill Class:</p> <pre><code>@Entity @IdClass(IdiomaEmpleadoId.class) @Table(name = "NO_IDIOMEMPLE") public class IdiomaEmpleado { @Id @ManyToOne(fetch = FetchType.LAZY) @JoinColumns(value = { @JoinColumn(name= "IEMCOMPANIA", referencedColumnName = "IGECOMPANIA"), @JoinColumn(name = "IEMEMPLEADO", referencedColumnName = "IGENUMEROIDENTIFIC") }) private Empleado empleado; @Id @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "IEMIDIOMA") private Idioma idioma; @Column(name = "IEMNIVELLECTURA") private String nivelLectura; //... } </code></pre> <p>Employee Language Skill Compound PrimaryKey Class:</p> <pre><code>public class IdiomaEmpleadoId { private EmpleadoId empleado; private String idioma; //... } </code></pre> <p>Language Class:</p> <pre><code>@Entity @Table(name = "NO_IDIOMAS") public class Idioma { @Id @Column(name = "IDICODIGO") private String codigo; @Column(name = "IDIDESCRIPCION") private String descripcion; //... } </code></pre> <p>I am using EclipseLink JPA2 Provider under a J2SE application and it is not giving me any exceptions.</p> <p>My questions are:</p> <ul> <li>Why is it not giving me exceptions? Is it not enforced to have Serializable?</li> <li>Is it safe to continue this way or should I definitely implemente serializable?.</li> <li>In which ones?, JPA2 Entities or PrimaryKey Classes?</li> </ul> <p>Thanks a lot for the help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload