Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

em.merge does not work while em.persist does?

843830Apr 27 2007 — edited Jan 21 2008
Hello,

I have a stateless session bean with code snippets below.
    @PersistenceContext
    private EntityManager em;
...
    public void setList(ContainerList list, int key) {
        ContainerList stored = (ContainerList)em.find(ContainerList.class, key);
        list.setId(key);
        if (stored == null) { em.persist(list); }
        else {
            em.merge(list); // 1st alternative
//            stored.copy(list); // 2nd alternative
        }
    }
...
When I call the method setList for a non existing key, the entity is stored in the database. When I call the method for an existing key, the old value is not updated by the new, i.e. the merge method has no effect. If I comment out the 2nd alternative, it has no effect either. Does anyone has an idea why this does not work? I am using Netbeans 5.5 and 5.5.1 release candidate 1. (With the included application server.)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 18 2008
Added on Apr 27 2007
6 comments
1,127 views