У меня есть 2 класса: User и UserPicture, которые имеют отношение 1: 1.
public class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id", nullable = false, unique = true)
private int id;
private String firstname;
private String lastname;
@OneToOne
@JoinColumn(name = "picture") //field named "picture" in the database
private UserPicture userPicture;
..
}
public class UserPicture {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id", nullable = false, unique = true)
private int id;
private Blob image;
@OneToOne
@JoinColumn(name = "user")
User user;
«user» в UserPicture будет загружен, а «userPicture» в User - нет - что я сделал не так?
ИЗМЕНИТЬ. Нужно добавить, что я просто создаю UserPicture и вставляю их (с существующим userId) - может быть, мне нужно каскадировать «user» в UserPicture?