Limitation of JPA 1.0 using @IdClass with *nested* composite primary keys?

前端 未结 3 1414
傲寒
傲寒 2020-12-21 13:16

Given the following example (departments - projects):

A department has the following properties (composite primary key):

@Entity
@IdClass(DeptId.clas         


        
3条回答
  •  长情又很酷
    2020-12-21 14:09

    The problem with the posted code is, that JPA 1.0 really doesn't allow nesting of composite primary key classes. This ProjectId is invalid:

    public class ProjectId implements Serializable
    {
        private String name;
        private DeptId dept;
    
        ...
    }
    

    DeptId has to be flattened, like:

    public class ProjectId implements Serializable
    {
        private Integer deptNumber;
        private String deptCountry;
        private String name;
    
        ...
    }
    

    I just got an EclipseLink version to go, but Hibernate has problems with that. I wonder how to tell Hibernate that JPA 1.0 is assumed.

提交回复
热议问题