hibernate lazy true error

时间:2011-01-12 13:01:31

标签: java hibernate lazy-loading

我在尝试将lazy true置于以下属性时遇到错误:

 <many-to-one name="ProductCategory" class="com.BiddingSystem.Models.Category" fetch="join" lazy="true">
            <column name="PRODUCTCATEGORY" />
        </many-to-one>

堆栈追踪:

Caused by: org.xml.sax.SAXParseException: Attribute "lazy" with value "true" must have a value from the list "false proxy no-proxy ".
        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.validateDTDattribute(XMLDTDValidator.java:1414)
        at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(XMLDTDValidator.java:1333)
        at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1940)
        at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:764)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
        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.util.xml.MappingReader.readMappingDocument(MappingReader.java:75)

4 个答案:

答案 0 :(得分:5)


 在多对一映射中不允许使用lazy =“true”。您应该使用false / proxy / no-proxy 感谢。

答案 1 :(得分:4)

来自Hibernate 3.1+ lazy =“true”已从DTD中移除(这是导致错误的原因)。 你应该使用lazy =“no-proxy”代替。

答案 2 :(得分:1)

Attribute "lazy" with value "true" must have a value from the list "false proxy no-proxy ".

它应该具有列表中的一个值:

false, proxy, no-proxy

您的答案已经在您的堆栈跟踪中。

答案 3 :(得分:0)

实际上,如果您使用lazy =“no-proxy”,则需要检测代码。对于默认的延迟加载,您应该使用“proxy”。

另请注意,lazy =“true / false / extra”对于Collection关联有效。