Coldfusion 未能延迟初始化集合…,无法初始化代理-无会话

Coldfusion 未能延迟初始化集合…,无法初始化代理-无会话,coldfusion,Coldfusion,我有一个应用程序,我正在扩展它以提供RESTAPI。在主站点中一切正常,但当我尝试使用REST API时,我在异常日志中看到以下内容: "Error","ajp-bio-8014-exec-3","12/02/14","12:54:06","table","failed to lazily initialize a collection of role: field, could not initialize proxy - no Session The specific sequence of

我有一个应用程序,我正在扩展它以提供RESTAPI。在主站点中一切正常,但当我尝试使用REST API时,我在异常日志中看到以下内容:

"Error","ajp-bio-8014-exec-3","12/02/14","12:54:06","table","failed to lazily initialize a collection of role: field, could not initialize proxy - no Session The specific sequence of files included or processed is: service.cfc'' "
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: field, could not initialize proxy - no Session
    at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:566)
    at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:186)
    at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:137)
    at org.hibernate.collection.internal.PersistentBag.size(PersistentBag.java:242)
    at coldfusion.runtime.xml.ListIndexAccessor.getSize(ListIndexAccessor.java:44)
    at coldfusion.runtime.xml.ArrayHandler.serialize(ArrayHandler.java:69)
    at coldfusion.runtime.xml.CFComponentHandler.serialize(CFComponentHandler.java:106)
    at coldfusion.runtime.XMLizerUtils.serializeXML(XMLizerUtils.java:83)
    at coldfusion.rest.provider.CFObjectProvider.writeTo(CFObjectProvider.java:378)
    at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1479)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
    at coldfusion.rest.servlet.CFRestServletContainer.service(CFRestServletContainer.java:141)
    at coldfusion.rest.servlet.CFRestServletContainer.service(CFRestServletContainer.java:86)
    at coldfusion.rest.servlet.CFRestServlet.serviceUsingAlreadyInitializedContainers(CFRestServlet.java:556)
    at coldfusion.rest.servlet.CFRestServlet.invoke(CFRestServlet.java:434)
    at coldfusion.rest.servlet.RestFilter.invoke(RestFilter.java:58)
    at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
    at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
    at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
    at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
    at coldfusion.rest.servlet.CFRestServlet.invoke(CFRestServlet.java:409)
    at coldfusion.rest.servlet.CFRestServlet.service(CFRestServlet.java:400)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
    at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:422)
    at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:198)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
禁用延迟加载将解决此问题,但会导致不可接受的性能(加载时间从200毫秒到22秒)。我不知道还能怎么处理

我是新来ColdFusion休息的,在我看来,CFC的处理方式很不寻常。它们似乎没有被初始化(init方法似乎没有运行),现在似乎ORM也没有得到同样的处理。我错过什么了吗

以下是产生此错误的代码摘录:

component rest="true" restpath="item" 
{
    import model.beans.*;

    remote item function getitem( numeric id restargsource="Path" ) restpath="{id}" httpmethod="GET"
    {
        var item = entityLoad("item",{ id = id },true);

        return item;
    }

}
豆子:

component persistent="true" table="item" output="false" extends="timestampedBean" batchsize="10" cacheuse="read-only"
{
    /* properties */

    property name="id" column="id" type="numeric" ormtype="int" fieldtype="id" generator="identity"; 
    property name="title" column="title" type="string" ormtype="string"; 
    property name="description" column="description" type="string" ormtype="string"; 
    property name="status" column="status" type="numeric" ormtype="byte" default="0" ; 
    property name="user" fieldtype="many-to-one" cfc="user" fkcolumn="userid" inversejoincolum="userid" lazy="true" cacheuse="read-only";
    property name="field" type="array" fieldtype="many-to-many" cfc="field" fkcolumn="id" linktable="items_fields" inversejoincolumn="fieldid" lazy="extra" batchsize="10" cacheuse="read-only";
}
我还注意到,在标准日志中,Hibernate正在记录查询,但随后它记录了“无会话”错误:


我可能还应该补充一点,这个“item”表是多对多关系的一部分,因此“collection of role:field”引用的是外部表。

org.hibernate.LazyInitializationException是一个常见的hibernate问题。根本原因是没有打开hibernate会话,因为没有可用的事务。 有几种方法可以克服这个问题。 请阅读以下链接:

或者你可以使用

在4.1.6版hibernate之后。更多信息请访问 将列表设置为空

例如:

迭代对象并将list every entity设置为null

entity.setList(null)


错误消息与ORM有关。发布您的
服务.cfc
和您希望工作但不适合您的代码?4.1.6中存在与连接泄漏相关的错误。最好使用4.1.7版本
Hibernate: 
    select
        item0_.id as id0_0_,
        item0_.dtcreated as dtcreated0_0_,
        item0_.dtmodified as dtmodified0_0_,
        item0_.title as title0_0_,
        item0_.description as descript6_0_0_,
        item0_.status as status0_0_,
        item0_.userid as userid0_0_ 
    from
        item item0_ 
    where
        item0_.id=?
Dec 2, 2014 15:23:00 PM Error [ajp-bio-8014-exec-3] - failed to lazily initialize a collection of role: field, could not initialize proxy - no Session The specific sequence of files included or processed is: service.cfc''