Issue
I have the following simple code iterating over a PersistentSet:
if (workers instanceof PersistentSet) {
for (Object worker : workers) { // failed to lazily initialize a collection of role: ...
}
}
I get the following exception:
failed to lazily initialize a collection of role...
What is the wrong thing in my code?
Solution
You need add to your field mapping fetch = FetchType.EAGER
.Hibernate use Lazy-loading by default.
Answered By - Tkachuk_Evgen
Answer Checked By - David Marino (JavaFixing Volunteer)