I want to initialize a collection with lazy fetch mode and use Join Fetch in my queries but I some times(not always) face with lazy initialization exception ???
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: xxx.entity.Product.producerEntities, could not initilaize proxy - no session ...
for example this query:
"select p from Product p left join fetch p.producerEntities"
and my persistence class:
class Product
{
Set<Producer> producerEntities = new HashSet<>();
....
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name="pid")
public Set<Producer> getProducerEntities(){
return producerEntities;
}
....
}
I don't understand what is the problem?
Problem was from my collection setter and getter methods name. It issolved.