Write the Hello World of Hibernate
The content is very simple, an entity Bean--student.java
A test file--studenttest.java
Two configuration files: Student.hbm.xml,hibernate.cfg.xml
But always error:
Exception in thread "main" Org.hibernate.MappingException:invalid configuration
caused by:org.xml.sax.SAXParseException; Linenumber:3; columnnumber:25; Invalid document: syntax not found.
I am really confused ah, are simple to not simple things, also reported wrong, but also clearly know that the configuration file is wrong, and then suspect that the problem is a jar package, there is doubt that the test was written wrong.
This evening myeclipse sudden kindness, incredibly give me a very detailed hint, clearly pointed out is hibernate.cfg.xml the second line error.
I then went to Hibernate's reference document to put their configuration files throughout the exam, and then modify, and then test incredibly gorgeous passed.
Sure enough, Hibernate.cfg.xml's file header went wrong.
The original file header is:
<?xml version= "1.0" encoding= "Utf-8"?>
Xmlns= "Http://www.hibernate.org/xsd/hibernate-configuration"
xsi:schemalocation= "Http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" >
The following changes are:
<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<! DOCTYPE hibernate-configuration Public
"-//hibernate/hibernate Configuration DTD 3.0//en"
"Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" >
Conclusion:
Can no longer go to other places to test the configuration file, the previous configuration file I copied from a project. It's better to go straight to the documentation.
Org.hibernate.MappingException:invalid Configuration