Lazy-loading doesn't work with Set
jblaufuss opened this issue · 0 comments
We are using Empire for the ORM layer of our application. We have several entities that have java.util.LinkedHashSet
collections that are annotated to be lazy-loading with @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
, however we are observing these entities being eager-loaded in our application despite the annotation.
I have spent some time debugging this, and it appears this is due to the way Empire's javaassist proxies are interacting with the java.util.LinkedHashSet
implementation: when the proxies are put
into the LinkedHashSet's backing LinkedHashMap
, the entity-proxy's hashCode()
method is called (from HashMap.hash(Object)
), which then triggers the ProxyHandler
to load the actual entity data. This can happen recursively, causing an eager load of quite a lot of entities despite the consistent use of FetchType.LAZY
.
We found this issue in the develop
branch (we pulled it in sometime in early 2016).