2009-10-14 43 views
2

背景DWR +彈簧+ JPA會議閉幕

我目前工作的應用程序使用了Spring + JPA。在我們決定引入DWR之前,一切正常。

使用DWR我調用Service類上的方法,然後重定向到Controller。

try{ 
     return WebContextFactory.get() 
         .forwardToString("/search.do?searchString=" + searchString); 
}catch(...){ 

} 

之後,在DAO中調用搜索方法時,它找不到筆會話。

Session session = (Session) entityManager.getDelegate(); 

這裏該會話關閉...

我想我(DWR引入的)的變化不應該以任何方式影響會話創建。

等待輸入。

Shardul。

+0

您的數據庫會話是如何處理的? – fglez 2009-10-14 08:03:53

+0

我使用連接池,如果這是你的意思要問。我注意到的另一件事是,似乎使用WebContextFactory ....發送給Controller的請求無法綁定到現有的EntityManager,並且它嘗試創建一個新的EntityManager ...它後來關閉了EntityManager ... 我正在發佈跟蹤... – 2009-10-14 08:28:29

回答

1

問題已解決。

問題是在web.xml中配置了OpenEntityManagerInViewFilter。它沒有攔截DWR請求,因爲它被映射到

*。做

,而不是

/*

Shardul。

0

這是跟蹤我在日誌中得到....


13:56:55,501 DEBUG DefaultAnnotationHandlerMapping:176 - Mapping [/search.do] to handler '[email protected]' 

13:56:55,517 DEBUG HandlerMethodInvoker:134 - Invoking request handler method: public java.lang.String com.xxxxx.controller.YGSearchController.search(java.lang.String,java.lang.String,int,int,boolean,boolean,javax.servlet.http.HttpServletRequest,org.springframework.ui.Model) 

13:56:55,517 DEBUG YGGenericDAO:29 - YGPropertyDAOImpl : In getPropertyIdsForName for Search Strings 

13:56:55,517 DEBUG SharedEntityManagerCreator$SharedEntityManagerInvocationHandler:189 - Creating new EntityManager for shared EntityManager invocation 

13:56:55,517 DEBUG SessionImpl:247 - opened session at timestamp: 12555088155 

13:56:55,517 DEBUG EntityManagerFactoryUtils:313 - Closing JPA EntityManager 

會話被打開,完全是處理請求之前關閉......


13:56:55,532調試 DispatcherServlet:588 - 不能在 com.x.service.impl.YGSearchServiceImpl.search(YGSearchServiceImpl.java:101)完成請求 顯示java.lang.NullPointerException


這是從控制檯跟蹤


org.hibernate.SessionException: Session is closed!在 org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72) 在

org.hibernate.impl.SessionImpl.createCriteria(SessionImpl.java:1535) 在 com.x.dao.impl .YGPropertyDAOImpl.getPropertyIdsForName(YGPropertyDAOImpl.java:32)


有何評論?