[hibernate-issues] [Hibernate-JIRA] Created: (EJB-261) merge fails to update join table

Bryan Hunt (JIRA) noreply at atlassian.com
Tue Jan 16 09:15:45 EST 2007


merge fails to update join table
--------------------------------

         Key: EJB-261
         URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-261
     Project: Hibernate Entity Manager
        Type: Bug

  Components: EntityManager  
    Versions: 3.2.1    
 Environment: Embedded entity manager 3.2.1 with DB2 or MySQL
    Reporter: Bryan Hunt
    Priority: Blocker


Doing a merge on an entity with a one to many relationship does not update the join table.

I have the following entities: 


@Entity 
public class Foo 
{ 
  ... 
  @OneToMany(cascade = CascadeType.ALL) 
  private Set<Bar> bars; 
} 

@Entity 
public class Bar 
{ 
  ... 
} 


The following works: 


Foo foo = new Foo(); 
Bar bar = new Bar(); 
foo.getBars().add(bar); 
em.getTransaction().begin(); 
em.persist(foo); // <<----------------- correctly updates the join table 
em.getTransaction().commit(); 

This also works:

Foo foo = em.find(Foo.class, id); 
Bar bar = new Bar(); 
foo.getBars().add(bar); 
em.getTransaction().begin(); 
em.persist(bar); 
em.merge(foo); // <<----------------- correctly updates the join table 
em.getTransaction().commit(); 

When this code executes the new Foo and Bar are persisted to the database, an entry is made into the join table, and all is well. 


The following fails: 

Foo foo = em.find(Foo.class, id); 
Bar bar = new Bar(); 
foo.getBars().add(bar); 
em.getTransaction().begin(); 
em.merge(foo); // <<----------------- does not update the join table 
em.getTransaction().commit(); 


When this code executes, the new Bar is persisted to the database, but the join table is not updated. 


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list