I am having troubles persisting @OneToMany relation in following Entities:
Code:
@Entity
Article {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
@JoinColumn(name="embed_id", referencedColumnName="id")
@MapKeyColumn(name = "language")
@MapKeyEnumerated(EnumType.ORDINAL)
private Map<Language, Locale> locales;
public void setLocale(Language l, Locale locale) {
locale.setLanguage(l);
locales.put(l, locale);
}
}
Code:
@Entity
Locale {
@Id
private Long embed_id;
@Id
private Language language;
@Column(length = 256)
private String name;
}
My problem is that when I try to persist the
Article, the
embed_id field of
Locale is still
null and I am getting:
ERROR: null value in column "embed_id" violates not-null constraint.
To summarize: I am not able to find out how to tell Hibernate to update the
embed_id of
Locale after persisting
Article and having its
id.
Thanks for any suggestions!