Hello,
I've some probleme with merge. My update method works in this way:
Code:
void update(Parent parent) {
evict(parent);
merge(parent);
}
My classes:
Code:
Parent {
Long id;
List<Children> childrens;
@OneToMany(targetEntity =ChildrenImpl.class, fetch=FetchType.LAZY)
@JoinColumn(name="PARENT")
@org.hibernate.annotations.Cascade(value = org.hibernate.annotations.CascadeType.ALL)
List<Children> getChildrens(){...}
@Id
Long getId() {...}
}
Code:
Children{
Parent parent;
@ManyToOne(targetEntity = ParentImpl.class, fetch = FetchType.LAZY)
@org.hibernate.annotations.Cascade(value = org.hibernate.annotations.CascadeType.ALL)
@JoinColumn(name = "PARENT", nullable = false)
Parent getParent(){...}
}
When i create a new Parent object and add new childrens and trying updated(evict & merge) then logs show me this after flush hibernate session:
Code:
INSERT PARENT //everythings here is ok.
INSERT CHILDREN // but without parent id(id=null)
Order is good but children doesn't have parent id in insert. Everything works fine when Parent is persisted in database, then childrens always have a good id.
Any ideas what should I do to get id from transient object(from persisted is ok).
Regards
KZ.