Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

Hibernate Search java.nio.channels.OverlappingFileLockException when index object

I have a web service running inside Tomcat 9 on an VPS instance. It uses Hibernate 5.4.12 and Hibernate Search 5.11.0. When I debug at local, my code work Ok. But after I deployed to server, I will get an OverlappingFileLockException when I try Index. I think the problem is on the VPS side, the permissions or the file management of the window.

This is my hibernate configuation:

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

This is the code to index one 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();
            }
        }
    }

This is my code to reindex all 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();
            }
        }
    }
question from:https://stackoverflow.com/questions/65891649/hibernate-search-java-nio-channels-overlappingfilelockexception-when-index-objec

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...