]
Evgeny Terentev commented on HHH-6761:
--------------------------------------
the same issue with two @OneToMany in one class with annotation FetchType.EAGER
hibernate generate two cross join and collection becomes more
CollectionTable and OneToMany, collection elements duplicate.
--------------------------------------------------------------
Key: HHH-6761
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6761
Project: Hibernate Core
Issue Type: Bug
Components: core
Environment: 3.6.4.Final
Reporter: Evgeny Terentev
@Entity
@Table(name = "aaa")
public class AAA implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@MapKey(name = "ccc")
@OneToMany(orphanRemoval = true, cascade = {CascadeType.REMOVE}, fetch =
FetchType.EAGER, mappedBy = "aaa")
private Map<CCC, BBB> bbb = new HashMap<CCC, BBB>();
@Column(name = "bonus_id")
@ElementCollection(targetClass = Long.class, fetch = FetchType.EAGER)
@CollectionTable(name = "aaa_bonus", joinColumns = @JoinColumn(name =
"advert_post_id"))
public Collection<Long> bonusIds;
}
@Entity
@Table(name = "bbb")
public class BBB implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int id;
@ManyToOne(optional = false)
@JoinColumn(name = "aaa_id", nullable = false)
public AAA aaa;
@Column
public CCC ccc;
@Column
public int value;
}
public enum CCC {
AAA,
BBB,
CCC,
}
first fill tables:
AAA a = new AAA();
a.bonusIds = Arrays.asList(1L, 2L, 3L); // size = 3
em.persist(a);
BBB b = new BBB();
b.aaa = a;
b.ccc = CCC.AAA;
b.value = 1;
em.merge(b);
em.merge(b);
second get bonusIds and check size:
AAA aaa = em.find(AAA.class, 6);
if (aaa.bonusIds.size() != 3)
throw new RuntimeException();
size will be 6! but must be 3.
generate sql:
select aaa0_.id as id1_1_, bbb1_.aaa_id as aaa4_1_3_, bbb1_.id as id3_, bbb1_.ccc as
formula0_3_, bbb1_.id as id0_0_, bbb1_.aaa_id as aaa4_0_0_, bbb1_.ccc as ccc0_0_,
bbb1_.value as value0_0_, bonusids2_.advert_post_id as advert1_1_4_, bonusids2_.bonus_id
as bonus2_4_
from aaa aaa0_
left outer join bbb bbb1_ on aaa0_.id=bbb1_.aaa_id
left outer join aaa_bonus bonusids2_ on aaa0_.id=bonusids2_.advert_post_id where
aaa0_.id=?
--
This message is automatically generated by JIRA.
For more information on JIRA, see: