Hello,
I have a class like this:
Code:
@Entity
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="parent_id")
@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
private Category parent;
@OneToMany(mappedBy="parent", fetch=FetchType.EAGER)
@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
@IndexColumn(name="list_id")
private List<Category> children = new ArrayList<Category> ();
}
when I put some categories on it by creating new one, and adding children, I got only inserts e.g.:
Hibernate: insert into Category (id, parent_id) values (null, ?, ?, ?, ?)
Hibernate: call identity()
Hibernate: insert into Category (id, parent_id) values (null, ?, ?, ?, ?)
Hibernate: call identity()
[... and more]
but parent_id remains null, there is no updates after saving entity, collection lost its parent, and also parent field remains null. What is wrong with such annotations, I think that generated id could be responsible for nulls, but shouldn't be launched updates after inserting collection?
Database memory HSQL.
best regards,
Adr
Solved I forgot to setParent on category, that's why it isn't assign ids :( Annotations are good for this problem.