I have a compound primary key formed by the next params :
@Entity @Table(name = "cita") @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "CITA_TYPE", discriminatorType = DiscriminatorType.STRING) @IdClass(CitaID.class) public class CitaEntity extends EntityObject {
private static final long serialVersionUID = 1L; @Id private String idCita; @ManyToOne private HistorialEntity historial; ... /** * Constructor por defecto sobrecargado con los elementos minimos necesarios */ public CitaEntity(CitaID identificador, EstadoCita estado,MedicoEntity medico) { this.idCita = identificador.getIdCita(); this.estado = estado; this.medico = medico; this.historial = new HistorialEntity(); } ...
I have defined citaID this way :
public class CitaID extends EntityObject {
private static final long serialVersionUID = 1L; private String idCita; private int historial;
public CitaID() { idCita = ""; historial = 0; }
public CitaID(String idCita, int historial) { this.idCita = idCita; this.historial = historial; }
public boolean equals(Object o){ return ((o instanceof CitaID) && (idCita.equals(((CitaID)o).getIdCita())) && (historial == ((CitaID)o).getHistorial())); } public int hashCode(){ return idCita.hashCode()+historial; } public String getIdCita() { return idCita; }
public int getHistorial() { return historial; } }
and the class "Historial" has the relation ...
@OneToMany(mappedBy="historial") private List<CitaEntity> listaCitas;
this works in the way that the class "cita" has many "historial", having a compound primary key . My problem appears with the constructor of citaEntity . Do I use the "CitaID" class ( the compound identifier) or I use the attributes ? . Finding an element works fine :
identificador = new CitaID("HOSP150620101504", 27); cita = em.find(CitaEntity.class, identificador);
but when I try to create a new element cita and persist it, it crashes with this message :
// identificador its the compund primary key cita = new CitaHospitalariaEntity(identificador, EstadoCita.pendiente_asignacion, hospital, medico);
...
org.hibernate.PropertyAccessException: could not set a field value by reflection setter of gestor.REH.entidades.CitaID.historial
|