Exception in thread “main” org.hibernate.HibernateException: Error accessing stax stream

纵饮孤独 提交于 2019-12-08 08:23:12

问题


I am making hibernate application using ubuntu trying to connect hibernate with mysql but this exception is arising. What should I have to do now to solve this?

Exception in thread "main" org.hibernate.HibernateException: Error accessing stax stream
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:107)
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:163)
at org.hibernate.cfg.Configuration.configure(Configuration.java:259)
at test.Client.main(Client.java:18)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8,16]
Message: The processing instruction target matching "[xX][mM][lL]" is not allowed.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:598)
at com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl.java:275)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:103)
... 5 more

回答1:


You have illegal symbols in hibernate.cfg.xml, probably spaces. Refer this for details

Error: The processing instruction target matching “[xX][mM][lL]” is not allowed.




回答2:


Here problem is hibernate could not locate your hibernate configuration file.

Hibernate default locate your Hibernate Configuration file in your resource folder.

If your Hibernate.cfg.xml file in your resource folder then check below line must be exist in your HibernateUtil class(There you configured hibernate SessionFactory).

sessionFactory = new Configuration().configure().buildSessionFactory();

If your Hibernate.cfg.xml file in differnt location the add below line in your HibernateUtil class.

sessionFactory = new Configuration().configure("/Path of your configuration file").buildSessionFactory();



来源:https://stackoverflow.com/questions/34527096/exception-in-thread-main-org-hibernate-hibernateexception-error-accessing-sta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!