繁体   English   中英

Hibernate 搜索 java.nio.channels.OverlappingFileLockException when index object

[英]Hibernate Search java.nio.channels.OverlappingFileLockException when index object

提示:本站提供中英文对照查看,鼠标放在中文字句上可显示英文原文。 若本文未解决您的问题,推荐您尝试使用帮您解决。

我有一个 web 服务在 VPS 实例上的 Tomcat 9 内运行。 它使用 Hibernate 5.4.12 和 Hibernate 搜索 5.11.0。 当我在本地调试时,我的代码工作正常 但是在我部署到服务器后,当我尝试使用 Index 时,我会得到一个OverlappingFileLockException 我认为问题出在VPS方面,window的权限或文件管理。

这是我的 hibernate 配置:

<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>

这是索引一个 object 的代码:

     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();
            }
        }
    }

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

    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();
            }
        }
    }
暂无回复试试使用:帮您解决问题。
暂无
暂无

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

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