zoukankan      html  css  js  c++  java
  • hibernate中错误笔记

    1.在写Student.hbm.xml 中, hibernate-mapping 中 指定类和数据库对应的表字段时,不小心将property写为properties,报错:

    ERROR: HHH000196: Error parsing XML (2) : The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)".
    Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
    at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:109)
    at org.hibernate.cfg.Configuration.add(Configuration.java:490)
    at org.hibernate.cfg.Configuration.add(Configuration.java:486)
    at org.hibernate.cfg.Configuration.add(Configuration.java:659)
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:742)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2197)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2169)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2149)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2102)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2017)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1996)
    at StudentTest.main(StudentTest.java:17)
    Caused by: org.xml.sax.SAXParseException: Element type "propertise" must be declared.
    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.handleStartElement(XMLDTDValidator.java:1929)
    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:2747)
    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:510)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
    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:107)
    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.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:78)
    ... 11 more
    原因是:property写成properties了

    property和properties都是同一个意思,他们之间的区别是什么呢?

    properties 是导入外部资源用的,后面接的是个路径 指向的是properties文件、

    2.用那个student.hbm.xml并且在hibernate.cfg.xml文件中,指定类时:

    <mapping resource="com/bjsxt/hibernate/Student.hbm.xml" />

    是 ‘/’ 不是‘.’

    <mapping resource="com.bjsxt.hibernate/Student.hbm.xml" />

    3.而用注解的方式时:

    就是在hibernate.cfg.xml文件中是用的  ‘.’

     4.在进行用注解的方式时:

    nested exception is org.hibernate.MappingException: 

    Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

    解决办法:缺少  javassist-3.15.0-GA.jar  包,版本不定。

  • 相关阅读:
    CodeForces 156B Suspects(枚举)
    CodeForces 156A Message(暴力)
    CodeForces 157B Trace
    CodeForces 157A Game Outcome
    HDU 3578 Greedy Tino(双塔DP)
    POJ 2609 Ferry Loading(双塔DP)
    Java 第十一届 蓝桥杯 省模拟赛 19000互质的个数
    Java 第十一届 蓝桥杯 省模拟赛 19000互质的个数
    Java 第十一届 蓝桥杯 省模拟赛 19000互质的个数
    Java 第十一届 蓝桥杯 省模拟赛十六进制转换成十进制
  • 原文地址:https://www.cnblogs.com/nucdy/p/5521335.html
Copyright © 2011-2022 走看看