Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

HI,

I am using Grails 1.2.1 and I always got this message when I run my apps and leave it without anyone using the apps.

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

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)

In my view I have load a class Menu:

/**

Menu Domain rule: one controller for one menu * */ class Menu { String menuName = ""; String menuController = ""; String menuAction = ""; Integer menuOrder = 1; String menuClass = ''; // html class Integer 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}";
}

}

and inside the layout/main.gsp I have this code:

                <%
            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>

How to fix this bug ? I can restart the grails and it work as normal.. but I just get curious how to fix this

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
144 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your bug seems related to stale connections when the application breaks after every few hours of inactivity.

See http://sacharya.com/grails-dbcp-stale-connections/ for the description and the solution of this issue.

Fabien.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...