Configure sessionFactory in hibernate in standalone application

蓝咒 提交于 2019-12-02 06:30:10
Damian Leszczyński - Vash

The problem is not related to Hibernate at all but to the XML structure.

The SAX Reader is set by Hibernate to use validation (org.hibernate.util.XMLHelper#createSAXReader(String,List,EntityResolver)

It goes more less like this:

SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);

Java dosc says

Method setValidating(boolean) - equests DTD validation and causes a failure if no DTD exists. If you only want schema validation and not DTD validation then use setValidating(false).

Your error says clear:

Caused by: org.xml.sax.SAXParseException: Document is invalid: no grammar found.

In this tutorial you will find all required information about hibernate conf file.

to fix it you will need to add:

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

You didn't declare any DTD in hibernate.cfg.xml

The message is saying that you are trying to validate the document, but no DTD has been declared, because no DOCTYPE declaration is present.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!