[英]Lazyloading rowcount error for Primefaces datatable using Hibernate
我正在嘗試為我的JSF數據表實現延遲加載,我的應用程序正在使用JSF2.0。 Spring 3和Hibernate 4。
我在DAO中有以下內容
@Override
public int getRequestCount() {
Query query = entityManager.createNamedQuery("Request.count");
return ((Long) query.getSingleResult()).intValue();
}
在ManagedBean中,我有
@Named("reqMB")
@Scope("request")
public class RequestManagedBean implements Serializable {
// other code .....
lazyModel.setRowCount(getRequestService().getRequestCount());
....
return lazyModel;
在實體類中
@Entity
@Table(name = "V_REQUESTS")
@NamedQueries({
@NamedQuery(name = "Request.count", query = "SELECT COUNT(r) FROM <viewname> r")
})
public class Request {
我面臨的問題是,當我嘗試將應用程序部署到weblogic 10.3.6時,出現以下異常。
Error creating bean with name 'requestDAOImpl': Injection of
autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private org.hibernate.SessionFactory
net.test.request.dao.RequestDAOImpl.sessionFactory; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'SessionFactory' defined in ServletContext resource
[/WEB-INF/applicationContext.xml]: Invocation of init method failed;
nested exception is org.hibernate.HibernateException:
Errors in named queries: Request.count
我該如何解決這個問題?
另一點是,除了使用以下代碼之外,還有其他方法可以獲取行數以進行延遲加載嗎?
@NamedQueries({
@NamedQuery(name = "Request.count", query = "SELECT COUNT(r)
FROM vw_request r")})
謝謝
我設法解決了這個問題,我犯的錯誤是我使用的是實際的視圖名稱,而不是類名稱,所以我改為
@NamedQuery(name = "Request.count", query = "SELECT COUNT(r) FROM Request r").
我的另一個疑問是沒有使用上面的方法獲取行數,我對我的DAO進行了如下修改,因此我不需要在Entity類中使用@NamedQuery。
int count = ((Long)sessionFactory.getCurrentSession().createQuery("select count(*)
from Request").uniqueResult()).intValue();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.