Struts+Hibernate+Spring出現異常錯誤,高手指點,謝謝!
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)
依賴注入配置省了
出現的異常為: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)
相關文章
- 此介面的實現物件是哪個?高手指點,謝謝!物件
- 編譯第四章程式的錯誤,請指點,謝謝!編譯
- 安裝是遇到錯誤,大家幫我看看,謝謝
- 我下載新的論壇,安裝出現錯誤,誰幫我解決下,謝謝
- 圖片上傳出錯--高手賜教!(謝謝)
- Tomcat服務問題,Cpu100%,急需幫助,請高手指點,謝謝!!!Tomcat
- jb7編譯發生錯誤,應該怎麼辦謝謝!!!編譯
- 重要問題,連結mysql錯誤,怎麼解決啊,謝謝大家MySql
- *****管理專家 V1.05版破解實錄 ,敬請高手指點,謝謝!!! (12千字)
- 請benq大哥說得明白點,謝謝ENQ
- ORA-07445 : 出現異常錯誤: 核心轉儲
- 請問這個報錯該怎麼解決,謝謝
- Uint8Array 我TM謝謝你不報錯哦UI
- 關於jive的幾個小問題,請高手指點,多謝先。
- 請求幫助!謝謝!
- activemq的問題,謝謝MQ
- ORA-07445 : 出現異常錯誤: 核心轉儲(一)
- B-Puzzle Version 5.0破解過程,請高手指點,謝謝!★強烈向初學破解者推薦★ (2千字)
- ORACLE 異常錯誤 錯誤號大全Oracle
- PHP錯誤和異常PHP
- jboss下jms開發出現如下錯誤,望那位大俠可以解決一下,多謝
- CTris 2000 Version2.0 破解過程,,請高手指點,謝謝!★強烈向初學破解者推薦★ (2千字)
- Jdon版jive安裝過程中,mysql資料庫連線出錯!(請幫幫忙,謝謝!)MySql資料庫
- 謝謝《瞭望智庫》的鼓勵
- 謝謝各位高手給個意見
- 急(啟動資料庫),謝謝資料庫
- ORA-07445: 出現異常錯誤: 核心轉儲 [kkqstcrf()+1355]CRF
- 來幫我看看這個簡單的遠端客戶端呼叫EJB出錯的例子,謝謝了客戶端
- 異常錯誤資訊處理
- python錯誤與異常Python
- Flutter之異常和錯誤Flutter
- Oracle異常錯誤處理Oracle
- ORACLE 異常錯誤處理Oracle
- php錯誤及異常捕捉PHP
- 《謝謝你遲到》學習筆記筆記
- 安裝jive3.1.5問題,謝謝
- 關於SimpleJdonFrameworkTest的問題,謝謝!Framework
- benq大哥,幫忙,請進入,謝謝!ENQ