Java Hibernate搜索未建立索引

Java Hibernate搜索未建立索引,java,spring,hibernate,lucene,hibernate-search,Java,Spring,Hibernate,Lucene,Hibernate Search,我使用hibernatesearch4.5.1编写Springweb应用程序。当我尝试搜索时,它返回emty列表。我认为索引中存在这个问题。已创建索引的目录,但在目录中保存实体后,文件不会更改 这是我的spring配置文件 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

我使用
hibernatesearch4.5.1
编写
Spring
web应用程序。当我尝试搜索时,它返回emty列表。我认为索引中存在这个问题。已创建索引的目录,但在目录中保存实体后,文件不会更改

这是我的spring配置文件

<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:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:security="http://www.springframework.org/schema/security"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/data/jpa
            http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-3.2.xsd">

    <context:component-scan base-package="project"/>
    <context:annotation-config/>

    <jpa:repositories base-package="project" transaction-manager-ref="hibernateTransactionManager"
                      entity-manager-factory-ref="entityManagerFactory"/>

    <bean id="entityManagerFactory" name="managerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="packagesToScan" value="project"/>
        <property name="dataSource" ref="postgresDataSource"/>
        <property name="validationMode" value="NONE"/>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL81Dialect</prop>
            </props>
        </property>
        <property name="persistenceProvider">
            <bean class="org.hibernate.jpa.HibernatePersistenceProvider"/>
        </property>

    </bean>


    <bean id="postgresDataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="org.postgresql.Driver"/>
        <property name="url" value="jdbc:postgresql://localhost:5432/LabourExchange"/>
        <property name="username" value="postgres"/>
        <property name="password" value="123456"/>
    </bean>

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

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

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="postgresDataSource"/>
        <property name="packagesToScan" value="project"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.postgres.dialect}</prop>
                <prop key="hibernate.max_fetch_depth">2</prop>
                <prop key="hibernate.jdbc.fetch_size">50</prop>
                <prop key="hibernate.jdbc.batch_size">8</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.hbm2ddl.auto">validate</prop>
                <prop key="hibernate.search.default.directory_provider">filesystem</prop>
                <prop key="hibernate.search.default.indexBase">/var/lucene/indexes</prop>
            </props>
        </property>
    </bean>

    <!--security config-->
    <security:http auto-config="true" use-expressions="true">
        <security:intercept-url pattern="/pages/**" access="isAuthenticated()"/>
        <security:form-login
                login-page="/auth/login.jsf"
                default-target-url="/pages/home.jsf"
                authentication-failure-url="/auth/login.jsf?status=error"/>
        <security:logout logout-success-url="/hello.jsf"/>
    </security:http>

    <security:authentication-manager>
        <security:authentication-provider user-service-ref="UserDetailsService">
        </security:authentication-provider>
    </security:authentication-manager>
</beans>

我搬家解决了这个问题

<prop key="hibernate.search.default.directory_provider">filesystem</prop>
<prop key="hibernate.search.default.indexBase">/var/lucene/indexes</prop>
文件系统
/var/lucene/指数

jpaProperties
tag

您是否提交了事务?Ralph,我使用JPA存储库保存方法保存了我的实体您是否提交了事务?Hibernate Search Reference 4.5,第2.1章“概述”-“为了更高效,Hibernate Search批量处理与Lucene索引的写交互…”“我在服务中使用@transactional注释
<prop key="hibernate.search.default.directory_provider">filesystem</prop>
<prop key="hibernate.search.default.indexBase">/var/lucene/indexes</prop>