[
http://opensource.atlassian.com/projects/hibernate/browse/EJB-261?page=co...
]
Bryan Hunt commented on EJB-261:
--------------------------------
I fail to see how commenting the merge operation, or any operation for that matter fixes
the problem. Especially since a comment is ignored by the compiler.
The Enterprise Java Beans 3.0 book says (page 157):
Another interesting thing about MERGE is that if you have added any new entities to a
relationship that have not been created in the database, they will be persisted and
created when the merge() happens:
Phone phone = new Phone();
phone.setNumber("617-666-6666");
cust.getPhoneNumbers().add(phone);
entityManager.merge(cust);
In this example, we allocate a Phone and add it to a Customer's list of phone numbers.
We then call merge() with the customer, and, since we have the MERGE CascadeType set on
this relationship, the persistence provider will see that is a new Phone entity and will
create it within the database.
Also, how is this only a minor issue? I have code that relies on merge() working as
indicated in the book, and since there is no workaround, I consider the issue a blocker.
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: Minor
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