I have a form to fill a POJO called Father
. Inside it, I have a FotoFather
field.
When I save a new Father, I save automatically the object FotoFather (with Hibernate ORM pattern).
FotoFather.fotoNaturalUrl
must be filled with the value of Father.id
and here is the problem!
When i'm saving Father
on the db, of course I still haven't Father.id
value to fill FotoFather.fotoNaturalUrl
. How can I solve this problem?
Thank you
@Entity
@Table(name = "father")
public class Father implements Serializable{
...
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
...
@OneToOne(targetEntity = FotoFather.class, fetch = FetchType.EAGER)
@JoinColumn(name = "fotoFather", referencedColumnName = "id")
@Cascade(CascadeType.ALL)
private FotoFather fotoFather;
}
FotoFather.class
@Entity
@Table(name = "foto_father")
public class FotoFather.class{
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
...
@Column(name = "foto_natural_url")
private String fotoNaturalUrl;
...
}