2
I’m trying to map a diary to an apprentice, where in the diary I have a Map<data,mensagem>
, that is, the date that was created and its respective message, but with the mapping that I did, I end up taking the following error:
Caused by: org.hibernate.MappingException:
Foreign key (FKr7nhfmr8w22h0h9ggc2oxd33r:aprendiz [diario_id])) must have same
number of columns as the referenced primary key (diario [id,data])
Apprentice Class:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Aprendiz extends Pessoa {
@OneToOne(cascade = {CascadeType.ALL})
private Diario diario;
//get, set, hashcode...
}
Classe Diario
@Entity
public class Diario implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@OneToOne(mappedBy = "diario")
private Aprendiz aprendiz;
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name = "data")
@Column(name = "texto")
@CollectionTable(name = "diario", joinColumns = @JoinColumn(name = "id"))
private Map<LocalDate, String> entrada = new HashMap<>();
//get, set, hashcode...
}