[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3332?page=c...
]
Vlad Mihalcea commented on HHH-3332:
------------------------------------
Hi,
This is my use case:
public class Round {
...
@OneToMany(fetch = FetchType.LAZY, mappedBy = "route")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.MERGE,
org.hibernate.annotations.CascadeType.REMOVE
})
@org.hibernate.annotations.Fetch(value =
org.hibernate.annotations.FetchMode.SUBSELECT)
public List<SubRound> getSubRoutes() {
return subRounds;
}
@Transient
public void addSubRoute(SubRound sr) {
if (sr != null) {
sr.setRoute(this);
getSubRoutes().add(sr);
}
}
...
}
public class SubRound {
...
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "route_id")
public Round getRoute() {
return route;
}
...
}
Round r1 = new Round();
r1 = getHibernateTemplate().merge(r1);
SubRound sr1 = new SubRound();
r1.addSubRoute(sr1);
getHibernateTemplate().merge(sr1);
There will be two SubRound(s) rows in the database.
Vlad
Hibernate duplicate then child entity's on merge
------------------------------------------------
Key: HHH-3332
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3332
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.2.6
Environment: JDK 1.6
Oracle 9i
Hibernate 3.2.6
Hibernate Annotations 3.3.1
Hibernate EntityManager 3.3.2
Standalone Running
Reporter: Rodrigo de Assumpção
Priority: Critical
Attachments: ExampleBug.zip
The method merge from EntityManager causes a duplication of child entity's.
class Father:
@OneToMany(mappedBy = "father", cascade={CascadeType.ALL},
fetch=FetchType.LAZY)
private List<Child> childList;
class Child:
@ManyToOne @JoinColumn(name = "ID_FATHER")
private Father father;
class BugTest
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("JpaTestHB");
EntityManager em = emf.createEntityManager();
Father f = (Father) em.createQuery("SELECT f FROM Father f WHERE f.id =
1").getSingleResult();
Child c = new Child();
c.setFather(f);
f.getChildList().add(c);
em.getTransaction().begin();
em.merge(f);
em.getTransaction().commit();
The execution of BugTest Class causes tow insert's on table "child".
If you change the fetch mode to EAGER (into Father class) the problem not occurs.
I make the same test with Toplink, and it make a unique insert, normal.
--
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