My problem is that I have an object A which contains a list of B Objects
开发者_Go百科@Entity
class A {
@OneToMany(cascade={CascadeType.MERGE})
List<B> list;
}
When I make a "merge" of an object A and then call "flush" inside a stateless EJB method
em.merge(a); //a is of class A
em.flush(); //doesn't flush "list"
it actually doesn't work. the ids of B objects of "list" are not set.
But persisting and flushing work
em.persist(a);
em.flush(); // it works!
The ids of B object of "list" are set.
I'm using EclipseLink. Does anybody know what could be happening?
it actually doesn't work because the ids of the B obects being part of the list "list" are not setted.
You should avoid using the id to implement equals/hashCode
, the contract shouldn't change while objects are in the List
. Anyway, I can't reproduce your problem with EclipseLink 2.0: a merge on A
cascades an insert on B
when I add a B
to the list.
精彩评论