I’m getting the error “Unable to find column with logical name: dniNumeros in org.hibernate.mapping.Table(alumno) and its related supertables and secondary tables” when using IdClass
I have tried using an EmbeddedId instead and I’m getting the same error. The column obviously exists in my database, because the code works perfectly fine when I remove the IdClass line from it
@Entity
@Table(name="dificultadalumnoejercicio")
@IdClass(DificultadAlumnoEjercicioPK.class)
public class DificultadAlumnoEjercicio implements Serializable {
private static final long serialVersionUID = -111454640507305257L;
@Id
@ManyToOne(cascade=CascadeType.MERGE)
@JoinColumns ({
@JoinColumn(name="alumnoDNINumeros", referencedColumnName="dniNumeros"),
@JoinColumn(name="alumnoDNILetra", referencedColumnName="dniLetra")
})
private Alumno alumno;
@Id
@OneToOne(cascade=CascadeType.MERGE)
@JoinColumn(name="ejercicioID", referencedColumnName="id")
private Ejercicio ejercicio;
@ManyToOne(cascade=CascadeType.MERGE)
@JoinColumn(name="dificultadID", referencedColumnName="id")
private Dificultad dificultad;
// Constructors / Getters / Setters
}
And here’s my IdClass
@Embeddable
public class DificultadAlumnoEjercicioPK implements Serializable {
private static final long serialVersionUID = 5559503979252689702L;
public Alumno alumno;
public Ejercicio ejercicio;
// Constructors / Getters / Setters
}
Here is my database code:
CREATE TABLE `dificultadAlumnoEjercicio` (
`alumnoDNINumeros` CHAR(8),
`alumnoDNILetra` CHAR,
`ejercicioID` INT,
`dificultadID` INT NOT NULL,
PRIMARY KEY (alumnoDNINumeros, alumnoDNILetra, ejercicioID),
FOREIGN KEY (alumnoDNINumeros, alumnoDNILetra) REFERENCES alumno(dniNumeros, dniLetra),
FOREIGN KEY (dificultadID) REFERENCES dificultad(id),
FOREIGN KEY (ejercicioID) REFERENCES ejercicio(id)
);
CREATE TABLE `alumno` (
`dniNumeros` CHAR(8),
`dniLetra` CHAR,
PRIMARY KEY (dniNumeros, dniLetra),
FOREIGN KEY (dniNumeros, dniLetra) REFERENCES persona(dniNumeros, dniLetra)
);
I have already asked in Stackoverflow and nobody answered, and all my friends that are knowledgeable of Hibernate and they all say my code should work, so I don’t know where to look for the answer