First of all: thanks for your answer.
It seems that there is still another problem, because I definetly do not delete the object twice!
I recognized that I have another problem, perhaps something with the Cascading-Types is wrong
My model is simple: Packages and Dependencies as connections between 2 Packages:
Code:
public class ModelPackage {
@OneToMany(
fetch = FetchType.EAGER,
cascade = CascadeType.MERGE,
mappedBy = "source")
private Set<Dependency> sourceDependencies = new HashSet<Dependency>();
@OneToMany(
fetch = FetchType.EAGER,
cascade = CascadeType.MERGE,
mappedBy = "target")
private Set<Dependency> targetDependencies = new HashSet<Dependency>();
...
}
and Dependency:
Code:
public class Dependency extends DiagramElement {
@ManyToOne (fetch = FetchType.EAGER, cascade=CascadeType.MERGE)
private ModelPackage source;
@ManyToOne (fetch = FetchType.EAGER, cascade=CascadeType.MERGE)
private ModelPackage target;
...
}
I can create 2 Packages and a Dependency between those 2 Packages and call merge() without any problems.
But if I do the following order:
create 2 Packages and a Dependency between those 2 Packages
merge();
create a third Package
merge()
create a fourth Package and a Dependency between Package 3 and Package 4
merge() -> Exception:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: xyz.Dependency
I am a little bit confused because I do not know why the first way works and the second doesn't...
Thanks in advance
Best regards
Alex