Merge for an entity with a non-cascading one-to-many collection fails if the collection contains transient objects
------------------------------------------------------------------------------------------------------------------
Key: HHH-1923
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1923
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.1.3, 3.2.0.cr3
Reporter: Manfred Geiler
With the EventManager example this bug is easy to reproduce.
The following fails with a TransientObjectException:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Event theEvent = new Event();
theEvent.setTitle("a title");
theEvent.setDate(new Date());
Person thePerson = new Person();
thePerson.setFirstname("foo");
thePerson.setLastname("bar");
theEvent.getParticipants().add(thePerson);
thePerson.addToEvent(theEvent);
session.merge(theEvent);
session.getTransaction().commit();
This is, because Hibernate tries to copy ALL values from the transient "event" object including ALL collection properties as well. Now, the "participants" Set contains a transient "person" which makes the CollectionType.replaceElements method fail.
The same applies when theEvent is a detached instead of a transient object:
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Event theEvent = new Event();
theEvent.setTitle("a title");
theEvent.setDate(new Date());
session.save(theEvent);
session.getTransaction().commit();
session.close();
session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Person thePerson = new Person();
thePerson.setFirstname("foo");
thePerson.setLastname("bar");
theEvent.getParticipants().add(thePerson);
thePerson.addToEvent(theEvent);
session.merge(theEvent);
session.getTransaction().commit();
session.close();
Suggested Solution:
Hibernate should not try to copy collections during merge if the collection is defined without cascade.
Thoughts?
--
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
|