Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 弹簧&x2B;带有开放会话分页的JSF不起作用_Java_Spring_Hibernate_Jsf - Fatal编程技术网

Java 弹簧&x2B;带有开放会话分页的JSF不起作用

Java 弹簧&x2B;带有开放会话分页的JSF不起作用,java,spring,hibernate,jsf,Java,Spring,Hibernate,Jsf,我对公开课有意见。首先,我使用Spring4.0+JSF2.2+Hibernate4.3。为了提供开放会话,我使用了org.springframework.orm.hibernate4.support.OpenSessionInViewFilter。 它部分工作,我从数据库中获取一些实体,呈现视图,并且延迟加载工作正常 然而,在呈现视图之后,我在p:dataGrid中使用分页,我得到了延迟初始化异常。我怎样才能避免呢?我希望只要管理bean存在,对象就会连接到会话。如何使分页工作不出现延迟初始化

我对公开课有意见。首先,我使用Spring4.0+JSF2.2+Hibernate4.3。为了提供开放会话,我使用了org.springframework.orm.hibernate4.support.OpenSessionInViewFilter。 它部分工作,我从数据库中获取一些实体,呈现视图,并且延迟加载工作正常

然而,在呈现视图之后,我在p:dataGrid中使用分页,我得到了延迟初始化异常。我怎样才能避免呢?我希望只要管理bean存在,对象就会连接到会话。如何使分页工作不出现延迟初始化错误

为了解决这个问题,我尝试使用检查我的管理bean中发生了什么。我不知道我是否理解正确,但是当我使用视图范围bean时,我认为始终应该有一个线程来处理这个bean。但当我打印线程id时,tomcat似乎会为每个请求使用新线程。这是正确的行为吗?以前,在不使用spring的情况下,我在视图过滤器中使用标准的open session,并将hibernate.current_session_context_class设置为org.hibernate.context.ThreadLocalSessionContext,一切正常。我尝试在这里使用相同的设置,但它会导致许多错误,我读到,当我使用spring提供的过滤器时,我不应该弄乱它。我使用Tomcat7.0.34和hibernate-C3P04.3

web.xml的一部分

<filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
    <init-param>
        <param-name>sessionFactoryBeanName</param-name>
        <param-value>sessionFactory</param-value>         
    </init-param>      
</filter>

<filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping> 

冬眠过滤器
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
sessionFactoryBeanName
会话工厂
冬眠过滤器
/*
要求
向前地
休眠配置:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

<tx:annotation-driven transaction-manager="transactionManager"/>

<bean 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>system.properties</value>
    </property>
</bean>

<bean id="dataSource" 
      class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.driverClassName}" />
    <property name="jdbcUrl" value="${jdbc.url}" />
    <property name="user" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />

    <!--        c3p0 props-->
    <property name="minPoolSize" value="${c3p0.minPoolSize}" />
    <property name="maxPoolSize" value="${c3p0.maxPoolSize}" />
    <property name="maxIdleTime" value="${c3p0.maxIdleTime}" />
    <property name="maxStatements" value ="${c3p0.maxStatements}" /> 

</bean>

<!-- Hibernate session factory -->
<bean id="sessionFactory" 
      class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource"/>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.validator.apply_to_ddl">false</prop>
        </props>
    </property>
    <property name="packagesToScan" value="com.efsf.ostoja" /> 
</bean>

<bean id="transactionManager" 
      class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

系统属性
org.hibernate.dialogue.mysqldialogue
真的
更新
假的

托管bean:

package com.efsf.ostoja.clientCase.view;

import com.efsf.ostoja.clientCase.logic.interfaces.ICaseService;
import com.efsf.ostoja.clientCase.model.ClientCase;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import lombok.Getter;
import lombok.Setter;

@ViewScoped
@ManagedBean
public class MarketMB implements Serializable{

  @Getter @Setter
  private List<ClientCase> cases;

  @ManagedProperty(value = "#{caseService}")
  @Getter @Setter
  private ICaseService service;

  @PostConstruct
  public void init(){
    cases=service.getAllActiveCases();
    System.out.println("Id: "+Thread.currentThread().getId());
  }


  public void test(){
    System.out.println("Id2: "+Thread.currentThread().getId());
  }
package com.efsf.ostoja.clientCase.view;
导入com.efsf.ostoja.clientCase.logic.interfaces.ICaseService;
导入com.efsf.ostoja.clientCase.model.clientCase;
导入java.io.Serializable;
导入java.util.List;
导入javax.annotation.PostConstruct;
导入javax.faces.bean.ManagedBean;
导入javax.faces.bean.ManagedProperty;
导入javax.faces.bean.ViewScoped;
进口龙目吸气剂;
进口龙目织机;
@视域
@ManagedBean
公共类MarketMB实现了可序列化{
@Getter@Setter
私人名单案件;
@ManagedProperty(value=“#{caseService}”)
@Getter@Setter
私人ICaseService服务;
@施工后
公共void init(){
cases=service.getAllActiveCases();
System.out.println(“Id:+Thread.currentThread().getId());
}
公开无效测试(){
System.out.println(“Id2:+Thread.currentThread().getId());
}
}

来自服务的方法:

@Override
@Transactional
public List<ClientCase> getAllActiveCases(){
    return  clientCaseDao.findAllByProperty("status", CaseStatus.NEW);
}
@覆盖
@交易的
公共列表getAllActiveCases(){
返回clientCaseDao.findAllByProperty(“status”,CaseStatus.NEW);
}
我的部分看法是:

<h:form>
  <p:dataGrid value="#{marketMB.cases}" var="c" id="paginatorTable" styleClass="simplePagination" paginator="true" rows="5" columns="1" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}">
    //some div with data here
  </p:dataGrid>
</h:form>

//这里有数据的一些div

它不起作用。
OpenSessionInViewFilter
可在单个请求通过
会话后立即对其进行处理。因此,由于会话不再存在,后续请求将失败。那么我可以使用什么其他解决方案使其工作呢?primefaces datagrid组件上的文档(不是演示页面,而是实际手册)应该能够告诉您这一点。同时,我发现了一个相关的问题,可以回答您的问题: