Hi Rich,

Are you serializing/deserializing the entity? If so you'll need to add the
following property to persistence.xml :
<property name="openjpa.DetachState" value="fgs(DetachedStateField=true)"/>

I have a similar set up that is working for me on OpenJPA 1.1.0-SNAPSHOT :

        Customer c = em.find(Customer.class, id);

        em.clear();  // detach

        assertNotNull( c.getAddress());

        c.setAddress(null);

        em.getTransaction().begin();

        Customer cPrime = em.merge(c);

        em.getTransaction().commit();

        assertNull(c.getAddress());
        assertNull(cPrime.getAddress());

        c = em.find(Customer.class, id);
        assertNull(c.getAddress ());

Relevant entity code :
public class Customer extends TestEntity implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = -5752300027182374895L;

    @GeneratedValue(strategy = GenerationType.AUTO)
    @Id
    Long id;

    @Version
    @Column(name = "VERSN")
    protected int version;

    @ManyToOne(targetEntity = Address.class , cascade = CascadeType.ALL)
    Address address;

Which version of OpenJPA are you using?

-Mike

On Dec 19, 2007 2:34 PM, Landers, Richard < [EMAIL PROTECTED]> wrote:

> Hello all,
>
> I'm having trouble using EntityManger.merge () operation...
>
> I have a entity A that holds a many-to-one reference to another, B. On
> entity A, the relationship is annotated like this:
>
> @ManyToOne(fetch=FetchType.EAGER, cascade=CascadeType.MERGE)
>
> At a certain point in processing, I've got a detached instance of A
> referencing an instance of B.
>
> I want to dissociate A from any instance of B.  So I call:
>
>    a.setB(null);
>
> while A is detached, and then call:
>
>    merge(a)
>
> I thought the merge() operation would discover the change and update A
> in the database, but it does not.
>
> Is my mental model wrong?
>
> Do I have to (or *can* I) mark A as "dirty" to get OpenJPA to notice it?
>
> Thanks in advance,
>
>  --Rich
>
>

Reply via email to