In this method, I have to fill out a collection, regardless of its type.
public void loadBeanCollectionItems(B bean, Collection collection, JSONArray collectionJson)
{
for(int index = 0; index < collectionJson.length(); index++)
{
collection.add(getBean(collectionJson.getJSONObject(index)));
}
}
but the following exception is generated:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:575)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:214)
at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:554)
at org.hibernate.collection.internal.AbstractPersistentCollection.write(AbstractPersistentCollection.java:399)
at org.hibernate.collection.internal.PersistentBag.add(PersistentBag.java:314)
at tools.json.AbstractBeanConverter.loadBeanCollectionItems(AbstractBeanConverter.java:224)
at tools.json.AbstractBeanConverter.loadBeanArray(AbstractBeanConverter.java:215)
at tools.json.AbstractBeanConverter.getBeanArray(AbstractBeanConverter.java:194)
at tools.json.AbstractBeanConverter.loadBeanFields(AbstractBeanConverter.java:177)
at tools.json.AbstractBeanConverter.loadBean(AbstractBeanConverter.java:156)
at tools.json.AbstractBeanConverter.getBean(AbstractBeanConverter.java:142)
at tools.json.AbstractBeanConverter.loadBeanFields(AbstractBeanConverter.java:174)
at tools.json.AbstractBeanConverter.loadBean(AbstractBeanConverter.java:156)
at tools.json.AbstractBeanConverter.getBean(AbstractBeanConverter.java:142)
at tools.json.AbstractBeanConverter.loadBeanCollectionItems(AbstractBeanConverter.java:224)
at tools.json.AbstractBeanConverter.loadBeanArray(AbstractBeanConverter.java:215)
at tools.json.AbstractBeanConverter.getBeanArray(AbstractBeanConverter.java:194)
at tools.json.AbstractBeanConverter.loadBeanFields(AbstractBeanConverter.java:177)
at tools.json.AbstractBeanConverter.loadBean(AbstractBeanConverter.java:156)
at tools.json.AbstractBeanConverter.getBean(AbstractBeanConverter.java:142)
at services.StartGame.doPost(StartGame.java:93)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
In this stack of exceptions the "AbstractBeanConverter.java:224" shortcut references the following line of this method:
collection.add(getBean(collectionJson.getJSONObject(index)));