欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-04-11 08:34:23
Hibernate 5.3.1 INFO: HHH000206: hibernate.properties not foundException in thread "main" org.hibernate.internal.util.config.ConfigurationException: U ......

 

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写法有问题。