Home > Net >  Why does only one Set get "... could not initialize prox - no Session"?
Why does only one Set get "... could not initialize prox - no Session"?

Time:02-10

So I have this project where I need to get some Information of all the TypeA and TypeB associated with the current object. getTypeAs() and getTypeBs() both return a Set<TypeA/B>. As far as I can tell both are mapped the exact same way in my hibernate mapping files and in the EntityE mapping. So why does only the getTypesBs() trigger an "could not initializ proxy ..."? Why are they not working the same way?

List<TypeA> tas = new ArrayList<TypeA>(current.getEntityD().getEntityE().getTypeAs());
List<TypeB> bas = new ArrayList<TypeA>(current.getEntityD().getEntityE().getTypeBs());

CodePudding user response:

Hi this could be due to how you open session. can try with changing fetch strategy from lazy load to Eager. Can check more options for this. https://www.baeldung.com/hibernate-initialize-proxy-exception

  •  Tags:  
  • Related