I think I also found a bug in their documentation. In their example,
(3.5.1Final), the id field is declared non-nullable.
@Entity
public class Parent {
@OneToMany
@OrderColumn(name="order")
@JoinColumn(name="parent_id", nullable=false)
private List<Child> children;
...
}
@Entity
public class Child {
...
@ManyToOne
@JoinColumn(name="parent_id", insertable=false, updatable=false, nullable=false)
private Parent parent;
...
}
I have something very similar, a MirexSubmission with a list of MirexNote's. I also make the cascade from MirexSubmision.
@Entity
@Table(name="mirex_submission")
public class MirexSubmission implements Serializable {
...
@OneToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE},fetch=FetchType.EAGER)
@OrderColumn(name="note_order")
@JoinColumn(name="submission_id")
public List<MirexNote> getNotes() {
return notes;
}
.....
}
@Entity
@Table(name="mirex_note")
public class MirexNote implements Serializable{
...
@ManyToOne
@JoinColumn(name="submission_id",insertable=false, updatable=false,nullable=true)
public MirexSubmission getSubmission() {
return submission;
}
...
}
However, it always give me some error when I try save (Hibernate merge()) about "no default value for "submission_id" column. It does not matter I merge the MirexNote or MirexSubmission object, in which case it cascade to MirexNote. I check the schema, "submission_id" column does not allow null value, but with out the default. And obviously, it is no wonder the insert on this table fail. Finally I change to
nullable=true
and things worked out.Correction (Aug. 3rd): It seems to work fine if both ends (many-to-many, one-to-many) set
nullable=false
.
No comments :
Post a Comment