添加 lucene 时 hibernate 配置文件出现错误

发布于 2024-10-10 02:32:36 字数 8098 浏览 5 评论 0原文

而遇到错误:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>

  <property name="hibernate.search.default.directory_provider">
       org.hibernate.search.store.FSDirectoryProvider
  </property>

  <property name="hibernate.search.default.indexBase">./lucene/indexes</property>
  <property name="hibernate.search.default.batch.merge_factor">10</property>
  <property name="hibernate.search.default.batch.max_buffered_docs">10</property>



           <event type="post-update"> 
                <listener 
           class="org.hibernate.search.event.FullTextIndexEventListener"/> 
            </event> 


            <event type="post-insert"> 
                <listener 
            class="org.hibernate.search.event.FullTextIndexEventListener"/> 
            </event> 

            <event type="post-delete"> 
                <listener 
            class="org.hibernate.search.event.FullTextIndexEventListener"/> 
            </event> 


            <event type="post-collection-recreate"> 
                <listener 
            class="org.hibernate.search.event.FullTextIndexEventListener"/> 
            </event> 


            <event type="post-collection-remove"> 
                <listener 
                class="org.hibernate.search.event.FullTextIndexEventListener"/> 
            </event> 

            <event type="post-collection-update"> 
                <listener 
               class="org.hibernate.search.event.FullTextIndexEventListener"/> 
            </event> 


        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost/postgres</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.connection.password">noor</property>
        <property name="hibernate.connection.pool_size">10</property>
        <property name="show_sql">true</property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="current_session_context_class">thread</property> 

        <property name="hibernate.search.default.indexBase"> 
            /users/application/indexes 
        </property>


        <mapping resource="com/BiddingSystem/Models/Users.hbm.xml"/>

        <mapping resource="com/BiddingSystem/Models/PersonalUser.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/BusinessUser.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/BusinessContactNumbers.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/Attribute.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/AttributeOption.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/Category.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/Item.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/Auction.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/Picture.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/Administrator.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

我正在尝试将 lucene 添加到我的应用程序中,但由于我的配置文件:堆栈跟踪

org.hibernate.MappingException: invalid configuration
 at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2211)
 at org.hibernate.cfg.Configuration.configure(Configuration.java:2128)
 at org.hibernate.cfg.Configuration.configure(Configuration.java:2107)
 at com.BiddingSystem.server.ServiceImpl.<init>(ServiceImpl.java:58)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 at java.lang.Class.newInstance0(Class.java:355)
 at java.lang.Class.newInstance(Class.java:308)
 at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
 at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
 at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:463)
 at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
 at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
 at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
 at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
 at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
 at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
 at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 at org.mortbay.jetty.Server.handle(Server.java:324)
 at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
 at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
 at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
 at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
 at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
 at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
 at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: org.xml.sax.SAXParseException: The content of element type "session-factory" must match "(property*,mapping*,(class-cache|collection-cache)*,event*,listener*)".
 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
 at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
 at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
 at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:2017)
 at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:901)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2938)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
 at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
 at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
 at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
 at org.dom4j.io.SAXReader.read(SAXReader.java:465)
 at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2208)
 ... 28 more

I am trying to add lucene to my application but i am running into error due to my configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>

  <property name="hibernate.search.default.directory_provider">
       org.hibernate.search.store.FSDirectoryProvider
  </property>

  <property name="hibernate.search.default.indexBase">./lucene/indexes</property>
  <property name="hibernate.search.default.batch.merge_factor">10</property>
  <property name="hibernate.search.default.batch.max_buffered_docs">10</property>



           <event type="post-update"> 
                <listener 
           class="org.hibernate.search.event.FullTextIndexEventListener"/> 
            </event> 


            <event type="post-insert"> 
                <listener 
            class="org.hibernate.search.event.FullTextIndexEventListener"/> 
            </event> 

            <event type="post-delete"> 
                <listener 
            class="org.hibernate.search.event.FullTextIndexEventListener"/> 
            </event> 


            <event type="post-collection-recreate"> 
                <listener 
            class="org.hibernate.search.event.FullTextIndexEventListener"/> 
            </event> 


            <event type="post-collection-remove"> 
                <listener 
                class="org.hibernate.search.event.FullTextIndexEventListener"/> 
            </event> 

            <event type="post-collection-update"> 
                <listener 
               class="org.hibernate.search.event.FullTextIndexEventListener"/> 
            </event> 


        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost/postgres</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.connection.password">noor</property>
        <property name="hibernate.connection.pool_size">10</property>
        <property name="show_sql">true</property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="current_session_context_class">thread</property> 

        <property name="hibernate.search.default.indexBase"> 
            /users/application/indexes 
        </property>


        <mapping resource="com/BiddingSystem/Models/Users.hbm.xml"/>

        <mapping resource="com/BiddingSystem/Models/PersonalUser.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/BusinessUser.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/BusinessContactNumbers.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/Attribute.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/AttributeOption.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/Category.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/Item.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/Auction.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/Picture.hbm.xml"/>
        <mapping resource="com/BiddingSystem/Models/Administrator.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

stack trace:

org.hibernate.MappingException: invalid configuration
 at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2211)
 at org.hibernate.cfg.Configuration.configure(Configuration.java:2128)
 at org.hibernate.cfg.Configuration.configure(Configuration.java:2107)
 at com.BiddingSystem.server.ServiceImpl.<init>(ServiceImpl.java:58)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 at java.lang.Class.newInstance0(Class.java:355)
 at java.lang.Class.newInstance(Class.java:308)
 at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
 at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
 at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:463)
 at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
 at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
 at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
 at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
 at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
 at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
 at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 at org.mortbay.jetty.Server.handle(Server.java:324)
 at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
 at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
 at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
 at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
 at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
 at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
 at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: org.xml.sax.SAXParseException: The content of element type "session-factory" must match "(property*,mapping*,(class-cache|collection-cache)*,event*,listener*)".
 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
 at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
 at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
 at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:2017)
 at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:901)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2938)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
 at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
 at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
 at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
 at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
 at org.dom4j.io.SAXReader.read(SAXReader.java:465)
 at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2208)
 ... 28 more

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-10-17 02:32:36

尝试将所有 标记放在底部。标签的顺序有时很重要(如果在 xsd 中如此定义)

Try placing all the <event> tags at the bottom. The order of tags is sometimes important (if defined so in the xsd)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文