解決辦法: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寫法有問題。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM