微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

索引对象时休眠搜索 java.nio.channels.OverlappingFileLockException

如何解决索引对象时休眠搜索 java.nio.channels.OverlappingFileLockException

我在 VPS 实例上的 Tomcat 9 中运行了一个 Web 服务。它使用 Hibernate 5.4.12 和 Hibernate Search 5.11.0。 当我在本地调试时,我的代码运行正常。但是在我部署到服务器之后,当我尝试使用 Index 时,我会得到一个 OverlappingFileLockException。我觉得是VPS方面的问题,是窗口的权限或者文件管理的问题。

这是我的休眠配置:

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.sqlServerDriver</property>
        <property name="hibernate.dialect">org.hibernate.dialect.sqlServer2012Dialect</property>
        <property name="hibernate.connection.url">jdbc:sqlserver://[IP Server];databaseName=hellojob_db</property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.connection.password">[password]</property>
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="show_sql">true</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.globally_quoted_identifiers">true</property>
        <property name="hibernate.show_sql">true</property>
        <!--<property name="hibernate.search.autoregister_listeners">false</property>-->
        <property name="hibernate.search.indexing_strategy">manual</property>
        <property name="hibernate.search.default.directory_provider">filesystem</property>
        <property name="hibernate.search.default.indexBase">C:/tvc/indexes</property>
        <property name="hibernate.id.new_generator_mappings">true</property>
        <property name="hibernate.transaction.flush_before_completion">true</property>
        <mapping package="com.hellojob.entities" />
        <mapping class="com.hellojob.entities.Users" />
        <mapping class="com.hellojob.entities.Customer" />
        <mapping class="com.hellojob.entities.RecruitmentInfo" />
        <mapping class="com.hellojob.entities.ERP_Admin" />
        <mapping class="com.hellojob.entities.ERP_AdminRole" />
        <mapping class="com.hellojob.entities.PositionAdmin" />
        <mapping class="com.hellojob.entities.WebsiteOrderContract" />
        <mapping class="com.hellojob.entities.WebsiteModule" />
        <mapping class="com.hellojob.entities.OrderContract" />
        <mapping class="com.hellojob.entities.PartnerCompany" />
        <mapping class="com.hellojob.entities.FormStructure" />
        <mapping class="com.hellojob.entities.Vocabulary" />
        <mapping class="com.hellojob.entities.VocabularyUsing" />
        <mapping class="com.hellojob.entities.VocabularyUsingType" />
        <mapping class="com.hellojob.entities.VocabularyAnswer" />
        <mapping class="com.hellojob.entities.VocabularyAnswerMapping" />
        <mapping class="com.hellojob.entities.Tvc_HistoryAcceptAuth" />
        <mapping class="com.hellojob.entities.Tvc_HistoryCustomer" />
        <mapping class="com.hellojob.entities.Tvc_HistoryCustomerObj" />
        <mapping class="com.hellojob.entities.WebsiteLanguage" />
        <mapping class="com.hellojob.entities.FavouriteOrderContract" />
        <mapping class="com.hellojob.entities.CustomerWish" />
        <mapping class="com.hellojob.entities.WebsiteLanguage" />
        <mapping class="com.hellojob.entities.FavouriteRecruitment" />
        <mapping class="com.hellojob.entities.EvaluatePartnerCompany" />
        <mapping class="com.hellojob.entities.Website_OrderBackground" />
        <mapping class="com.hellojob.entities.VocabularyShared" />
        <mapping class="com.hellojob.entities.Website_OrderContractgallery" />
        <mapping class="com.hellojob.entities.SaleNews" />
        <mapping class="com.hellojob.entities.Customer_gallery" />
        <mapping class="com.hellojob.entities.UserReport" />
        <mapping class="com.hellojob.entities.UserReportReason" />
        <mapping class="com.hellojob.entities.NotificationType" />
        <mapping class="com.hellojob.entities.UserNotification" />
        <mapping class="com.hellojob.entities.JobProvince" />
        <mapping class="com.hellojob.entities.SaleNewsTransactionDetail" />
        <mapping class="com.hellojob.entities.SaleNewsTransaction" />        
        <mapping class="com.hellojob.entities.HistoryAffiliate" />
    </session-factory>
</hibernate-configuration>

这是索引一个对象的代码

     public static void indexOne(int id) throws Exception {
        Session session = null;
        FullTextSession fullTextSession = null;
        Transaction tx = null;
        try {
            if (session != null) {
                session = HibernateConfiguration.getInstance().openSession();
                fullTextSession = Search.getFullTextSession(session);
                tx = fullTextSession.beginTransaction();
                Object order = fullTextSession.load(WebsiteOrderContract.class,id);
                fullTextSession.index(order);
                tx.commit();
            }
        } catch (Exception e) {
            HibernateConfiguration.getInstance().rollbackTransaction(tx);
            throw e;
        } finally {
            HibernateConfiguration.getInstance().closeSession(session);
            try {
                if (fullTextSession != null && fullTextSession.isopen()) {
                    fullTextSession.close();
                }
            } catch (Exception e) {
                e.printstacktrace();
            }
        }
    }

这是我重新索引所有对象的代码

    public static void indexAll() throws Exception {
        Session session = null;
        FullTextSession fullTextSession = null;
        try {
            session = HibernateConfiguration.getInstance().openSession();
            if (session != null) {
                fullTextSession = Search.getFullTextSession(session);
                fullTextSession.createIndexer().startAndWait();
            }
        } catch (Exception e) {
            throw e;
        } finally {
            HibernateConfiguration.getInstance().closeSession(session);
            try {
                if (fullTextSession != null && fullTextSession.isopen()) {
                    fullTextSession.close();
                }
            } catch (Exception e) {
                e.printstacktrace();
            }
        }
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。