[hibernate-dev] Eager fetch and duplicates of collection elements
Gunnar Morling
gunnar at hibernate.org
Thu Feb 11 08:48:11 EST 2016
Hi,
I understand that $subject is a known source of confusion for people
when working with HQL/criteria queries and not applying something like
DistinctRootEntityResultTransformer.
I am seeing the same behaviour though when getting a root entity by id
and join-fetching two (nested) collections. That's my model:
@Entity
public class Parent {
@Id @GeneratedValue
private Long id;
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name = "parent_id")
private List<Child> children = new ArrayList<>();
}
@Entity
public class Child {
@Id @GeneratedValue
private Long id;
@ElementCollection(fetch=FetchType.EAGER)
@JoinTable(name = "Child_Properties")
@MapKeyColumn(name = "key")
@Column(name = "value")
private Map<String, String> properties = new HashMap<>();
}
I am persisting a parent with one Child which has three "properties"
entries. Loading the Parent by id yields three elements in the
"children" list:
Parent loaded = session.get( Parent.class, 123 );
assert 1 == loaded.getConfigurations().size(); // <!-- Fails, it
contains the same Child three times
I don't think that's expected?
I can file an issue, but first wanted to make sure I am not missing
anything obvious.
Thanks,
--Gunnar
More information about the hibernate-dev
mailing list