无法初始化代理 - 没有会话

时间:2010-05-12 09:39:49

标签: java hibernate grails groovy

HI,

我正在使用Grails 1.2.1,当我运行我的应用程序并且没有任何人使用应用程序时,我总是收到此消息。

  

org.hibernate.LazyInitializationException:无法初始化代理 - 没有会话

at H__project_ilinkdev_grails_app_views_layouts_main_gsp$_run_closure2.doCall(H__project_ilinkdev_grails_app_views_layouts_main_gsp:220)

at H__project_ilinkdev_grails_app_views_layouts_main_gsp$_run_closure2.doCall(H__project_ilinkdev_grails_app_views_layouts_main_gsp)

at H__project_ilinkdev_grails_app_views_layouts_main_gsp.run(H__project_ilinkdev_grails_app_views_layouts_main_gsp:259)

at org.jsecurity.web.servlet.JSecurityFilter.doFilterInternal(JSecurityFilter.java:382)

at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:180)

at java.lang.Thread.run(Thread.java:619)

在我看来,我加载了一个课程菜单:

/**

菜单域   规则:一个菜单的一个控制器  *  * / class Menu {     String menuName =“”;     String menuController =“”;     String menuAction =“”;     整数menuOrder = 1;     String menuClass =''; // html类     整数myid = 0;

boolean isUser = false; // is this user menu (user only menu) 
boolean isAdmin = false; // is this administrator menu 
boolean isHorizontal =false; // is this horizontal or vertical (if false)
String menuType='all'; // pia, dam, da, br, all  
Menu parentMenu;

static hasMany = [childMenu:Menu] ;
static belongsTo = [parentMenu:Menu];

static constraints = {
    menuName(blank:false, nullable:false);
    menuOrder(blank:false, nullable:false);
    menuController(blank:true,nullable:false); // blank/nullable if there is no controller
    menuAction(blank:true,nullable:false); // blank/nullable if there is no controller
    menuClass(blank:true,nullable:false); // css class ... blank : using default menu
    parentMenu(blank:true, nullable:true);
    childMenu(blank:true, nullable:true);
}

String toString(){
    "${menuName}";
}

}

并在layout / main.gsp中 我有这段代码:

                <%
            def currMenu = Menu.findByMenuController(params.controller);
            %>
            <g:if test="${currMenu}">
            <g:if test="${currMenu.isHorizontal}">
            <g:each in="${Menu.findAllByParentMenu(currMenu,[sort:'menuOrder',order:'asc'])}" status='x' var='submenu'>
            <li class='${submenu.menuClass} <% 
            if(submenu.menuController == params.controller){
                // dont hi-light on sign out 
                if(params.controller.equals("auth")){
                }else{
                    out << "selected";
                }
            }
            %>'> 
                    <g:if test="${!submenu.menuController.equals('')}">
                        <g:link controller='${submenu?.menuController}' action='${submenu?.menuAction}'>
                            ${submenu?.menuName} 
                        </g:link>
                    </g:if>
                    <g:else>
                            ${submenu?.menuName} 
                    </g:else>
                </li>
            </g:each>
            </g:if>
            <g:else>
            <%
            // get who is the parent 
            def parentMenu = currMenu.parentMenu ;
            %> 
            <g:each in="${Menu.findAllByParentMenu(parentMenu,[sort:'menuOrder',order:'asc'])}" status='x' var='submenu'>
            <li class='${submenu.menuClass} <% 
            if(submenu.menuController == params.controller){
                // dont hi-light on sign out 
                if(params.controller.equals("auth")){
                }else{
                    out << "selected";
                }
            }
            %>'> 
                <g:if test="${!submenu.menuController.equals('')}">
                    <g:link controller='${submenu?.menuController}' action='${submenu?.menuAction}'>
                        ${submenu?.menuName} 
                    </g:link>
                </g:if>
                <g:else>
                        ${submenu?.menuName} 
                </g:else>
            </li>
            </g:each>
            </g:else>
            </g:if>
        </ul>
        </g:if>

如何修复此错误?我可以重新启动grails并且它正常工作..但我只是好奇如何解决这个问题

1 个答案:

答案 0 :(得分:1)

当应用程序在每几个小时不活动后中断时,您的错误似乎与过时的连接有关。

有关此问题的说明和解决方案,请参阅http://sacharya.com/grails-dbcp-stale-connections/

小煜。