views:

56

answers:

1

My problem is that I have an object A which contains a list of B Objects

@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 setted.

But persisting and the flushing works

em.persist(a);
em.flush(); // it works!

The ids of B object of "list" are setted.

I'm using EclipseLink. Does anybody knows what could be happen?

A: 

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.

Pascal Thivent