• 解决办法:Message: 对实体 "useUnicode" 的引用必须以 ';' 分隔符结尾


    Hibernate 5.3.1 版本下出现此问题:

    INFO: HHH000206: hibernate.properties not found
    Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null
        at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:133)
        at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)
        at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
        at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:165)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:244)
        at test.Service.saveModify(Service.java:34)
        at test.App.main(App.java:15)
    Caused by: javax.xml.bind.UnmarshalException
     - with linked exception:
    [javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8,113]
    Message: 对实体 "useUnicode" 的引用必须以 ';' 分隔符结尾。]
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:470)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:448)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:420)
        at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:126)
        ... 7 more
    Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8,113]
    Message: 对实体 "useUnicode" 的引用必须以 ';' 分隔符结尾。
        at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:596)
        at com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl.java:276)
        at javax.xml.stream.util.EventReaderDelegate.peek(EventReaderDelegate.java:104)
        at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor$NamespaceAddingEventReader.peek(JaxbCfgProcessor.java:254)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.handleCharacters(StAXEventConnector.java:164)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.bridge(StAXEventConnector.java:126)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:445)
        ... 9 more

    原因:
    <property name="hibernate.connection.url">标签内容格式有误:

    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/lvlang?" +"autoReconnect=true&useUnicode=true&characterEncoding=UTF-8</property>

    后参考对实体 “characterEncoding” 的引用必须以 ‘;’ 分隔符结尾,将&符号重写成:&amp;如下:

    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/lvlang?" +"autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8</property>

    如是问题解决。

    其实根据异常提示–“Message: 对实体 “useUnicode” 的引用必须以 ‘;’ 分隔符结尾”,也知道应该是useUnicode附近写的有问题。

    前半截异常提示,容易误导人以为是配置文件或者标签名的问题:

    INFO: HHH000206: hibernate.properties not found
    Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null

    其实真正的问题出在caused by后面:

    Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8,113]
    Message: 对实体 "useUnicode" 的引用必须以 ';' 分隔符结尾。
        at 

    另外,Eclipse 对于 XML 文件的错误提示,实在不友好,如上错误的 xml 写法,Eclipse 的错误提示是The word 'localhost' is not correctly spelled + The word 'lvlang' is not correctly spelled,误导人以为是localhost或者lvlang写法有问题。

  • 相关阅读:
    2021微软Power BI 每月功能更新系列——Power BI 6月版本功能完整解读 ​
    Power Automate实例应用
    微软Power BI 每月功能更新系列——2021年4月版本功能更新全面解读
    Power Apps 应用:构建一套简易的五一休假报备管理系统(一)
    如何在Azure上使用 Python 创建ADF
    微软Power BI 每月功能更新系列——2021年3月版本功能更新全面解读
    Power BI 制作技巧 — 按钮动画效果
    连接到Power BI Premium或 Azure Analysis Services时,如何更改Excel中的用户帐户
    在 Power BI 中连接到 SAP HANA 数据库
    2021微软Power BI 每月功能更新系列——Power BI 2月版本功能完整解读
  • 原文地址:https://www.cnblogs.com/lvlang/p/10586336.html
Copyright © 2020-2023  润新知