Struts+Hibernate+Spring出現異常錯誤,高手指點,謝謝!

mhbjava發表於2005-12-01
Struts+Hibernate+Spring出現異常錯誤,高手指點,謝謝!

依賴注入配置省了
出現的異常為:Failed to lazily initialize a collection - no session or session was closed
謝謝!

QueryManager.java類
public interface QueryManager {
public List find( String query );
}

HibernateQueryManager.java類:
public class HibernateQueryManager extends HibernateDaoSupport implements QueryManager
{
public List find( String query ) {
return getHibernateTemplate().find( query );

}
}

ContactService.java
public interface ContactService
{
public List findContactsByUser( String userName ) ;
}

ContactService.java的實現類ContactServiceImpl.java
public class ContactServiceImpl extends BaseService implements ContactService
{
public List findContactsByUser( String userName )
{
User user = _userService.findUserByName( userName );
String sql = "from Contact as contact where contact.fromUser.id = '" + user.getId().toString() + "' order by contact.id desc";

return qm.find( sql );
}
}

UserService.java
public interface UserService
{
public User findUserByName( String name ) ;
}

UserService.java的實現類UserServiceImpl.java
public class UsersServiceImpl extends BaseService implements UserService
{
public User findUserByName( String name )
{
List list = qm.find( "from User where username= ? ", name );
if( list.size() > 0 ) return (User)list.get(0);
return null;
}
}

action類接受頁面傳遞過來的資料
AlbumAction.java

public class AlbumAction extends BaseAction
{
public ActionForward addAdmin(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {

String username = (String) request.getParameter("user");
User user = _userService.findUserByName( username );
request.setAttribute( "user", user );
request.setAttribute( "isOwner", isOwner( username ) );
List listFriends = _contactService.findContactsByUser(username); //跟蹤除錯發現listFriends.size()>=1(即是有資料的,資料可以查詢出來)
System.out.println("ok");
request.setAttribute("listFriends",listFriends); //在這裡出現錯誤:請高手指點 Failed to lazily initialize a collection - no session or session was closed
System.out.println("test");
return mapping.findForward("addAdmin");

}
}


以上類之間的關係:

頁面------>AlbumAction------>ContactServiceImpl---------->UserServiceImpl
---------->HibernateQueryManager


出現的異常為:
javax.servlet.ServletException: Failed to lazily initialize a collection - no session or session was closed
net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter.doFilter(SecurityEnforcementFilter.java:214)
net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
net.sf.acegisecurity.ui.basicauth.BasicProcessingFilter.doFilter(BasicProcessingFilter.java:212)
net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
net.sf.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:153)
net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
net.sf.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:114)
net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
net.sf.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:374)
net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:225)
net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
net.sf.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:179)
net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:125)
dragonchant.framework.web.EncodingFilter.doFilter(EncodingFilter.java:37)

相關文章