Dear all,
I've a question for you.
I've to implement with annotation a one to many relation between object paziente and another object.
I post some code.
When I add a Paziente object, other object is saved, but foreign key (paziente_id) is always null.
I missed something with foreign key.
Could you help me?
Code:
public class Paziente implements java.io.Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "ID_PAZIENTE")
private long idPaziente;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="ID_ANAGRAFICA")
private pzAnagrafica cAnagrafica;
[b]@OneToMany(mappedBy="paziente_fk",cascade = CascadeType.ALL)
private Set<pzAnamnFisioAllergia> allergie = new HashSet<pzAnamnFisioAllergia>(0);
public Set<pzAnamnFisioAllergia> getAllergie() {
return this.allergie;
}
public void setAllergie(Set<pzAnamnFisioAllergia> allergie) {
this.allergie = allergie;[/b]
}
public Paziente() {
}
}
Code:
@Entity
@Table(name = "an_fis_allergia")
public class pzAnamnFisioAllergia implements java.io.Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "ID_ALLERGIA")
private long idAllergia;
@ManyToOne
@JoinColumn(name="paziente_fk", insertable=false, updatable=false)
private Paziente paziente_fk;
public Paziente getPaziente()
{
return paziente_fk;
}
could you help me?
Where I'm going wrong?
In the child table, my parent is always NULL...
Thanks