the argument of merge() got corrupted
-------------------------------------
Key: HHH-6629
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6629
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.7, 3.6.3
Environment: MySQL, Oracle
Reporter: Vladimir Tsichevski
The object passed to the EntityManager.merge() method sometimes got corrupted while the
merge() is executed. This happens if
1. The entity has a @OneToMany field.
2. The @OneToMany field type is the same as or derivative of the owner type
3. The entity has a composite @Id
As the result, the owner object receives @Id fields from one of its @OneToMany field
collection members.
This is due to that the parent object (owner) is sometimes used as the target template
when children are merged in org.hibernate.type.ComponentType.replace() method (lines
460-462 in 3.6.7):
final Object result = target == null
? instantiate( owner, session )
: target;
which calls the org.hibernate.type.EmbeddedComponentType.instantiate method (lines
51-61):
public Object instantiate(Object parent, SessionImplementor session)
throws HibernateException {
final boolean useParent = parent!=null &&
//TODO: Yuck! This is not quite good enough, it's a quick
//hack around the problem of having a to-one association
//that refers to an embedded component:
super.getReturnedClass().isInstance(parent);
return useParent ? parent : super.instantiate(parent, session);
}
as you may see, if useParent is true, the parent object (owner) is used as the template to
update children!
IMHO this must either be fixed or documentations shall say valuable objects must never be
passed to merge()
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira