我有一些类似于这个的JPA,但当我尝试坚持一个有proyects的员工时,我得到:
我做错了什么?
@Entity
@Table(name="EMPLOYEES")
public funal class Employee {
@Id
@SequenceGenerator(name="EMPLOYEES_ID_GENERATOR", sequenceName="EMPLOYEES_ID_SEQ")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator("EMPLOYEES_ID_GENERATOR")
private Long id;
private String field1;
@Temporal(TemporalType.DATE)
private Date field2;
@OneToMany(mappedBy="employee", cascade=CascadeType.ALL)
private Set<EmployeeProyect> employeeProyects;
// bla bla
}
@Entity
@Table(name="PROYECTS")
public funal class Proyect {
@Id
@SequenceGenerator(name="PROYECTS_ID_GENERATOR", sequenceName="PROYECTS_ID_SEQ")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator("PROYECTS_ID_GENERATOR")
private Long id;
private String field1;
@Temporal(TemporalType.DATE)
private Date field2;
@OneToMany(mappedBy="proyect")
private Set<EmployeeProyect> employeeProyects;
// bla bla
}
@Entity
@Table(name="EMPLOYEEPROYECTS")
public final class EmployeeProyect {
@EmbeddedId
private EmployeeProyectPK id;
@ManyToOne
@MapsId("idEmployee")
@JoinColumn(name="ID_EMPLOYEE", insertable=false, updatable=false)
private Employee employee;
@ManyToOne
@MapsId("idProyect")
@JoinColumn(name="ID_PROYECT", insertable=false, updatable=false)
private Proyect proyect;
private string commonField;
// bla bla
}
@Embeddable
public final class EmployeeProyectPK {
@Column(name="ID_EMPLOYEE")
private long idEmployee;
@Column(name="ID_PROYECT")
private long idProyect;
// bla bla
}