简体   繁体   English

使用Hibernate延迟Primefaces数据表的行加载行计数错误

[英]Lazyloading rowcount error for Primefaces datatable using Hibernate

I am trying to implement lazy loading for my JSF datatable, my application is using JSF2.0. 我正在尝试为我的JSF数据表实现延迟加载,我的应用程序正在使用JSF2.0。 Spring 3 and Hibernate 4. Spring 3和Hibernate 4。

I have the following in DAO 我在DAO中有以下内容

@Override
public int getRequestCount() {          
    Query query = entityManager.createNamedQuery("Request.count");
    return ((Long) query.getSingleResult()).intValue();
}

and in ManagedBean I have 在ManagedBean中,我有

@Named("reqMB")
@Scope("request")
public class RequestManagedBean implements Serializable {

// other code .....    
lazyModel.setRowCount(getRequestService().getRequestCount());
....
return lazyModel;

in Entity class 在实体类中

@Entity
@Table(name = "V_REQUESTS")
@NamedQueries({
    @NamedQuery(name = "Request.count", query = "SELECT COUNT(r) FROM <viewname> r")
})
public class Request {

The problem I am facing is when I try to deploy my application to weblogic 10.3.6, I am getting the following exception. 我面临的问题是,当我尝试将应用程序部署到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

How can I resolve this issue? 我该如何解决这个问题?

Another point is instead of using the following, are there any other ways of getting rowcount for lazyloading? 另一点是,除了使用以下代码之外,还有其他方法可以获取行数以进行延迟加载吗?

@NamedQueries({
    @NamedQuery(name = "Request.count", query = "SELECT COUNT(r) 
    FROM vw_request r")})

Thanks 谢谢

I have managed to resolve the issue, mistake I made was instead of Class name I have used actual view name, so I changed to 我设法解决了这个问题,我犯的错误是我使用的是实际的视图名称,而不是类名称,所以我改为

@NamedQuery(name = "Request.count", query = "SELECT COUNT(r) FROM Request r").

My other doubt was without using the above to get the rowcount, I have modified my DAO as follows, with this I do not need to have @NamedQuery in Entity class. 我的另一个疑问是没有使用上面的方法获取行数,我对我的DAO进行了如下修改,因此我不需要在Entity类中使用@NamedQuery。

int count = ((Long)sessionFactory.getCurrentSession().createQuery("select count(*) 
from Request").uniqueResult()).intValue();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM