[
http://opensource.atlassian.com/projects/hibernate/browse/EJB-261?page=all ]
Emmanuel Bernard resolved EJB-261:
----------------------------------
Resolution: Fixed
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
Assignee: Emmanuel Bernard
Priority: Minor
Fix For: 3.3.0.ga
Attachments: hibernate.bug.zip
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira