Exception in thread \"main\" org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/lara/Person.hbm.xml
at org.hibernate.cfg.C
it's simple
1.create constructor
public Person(){}
this is main thing in hibernate. it will map the object through this constructor(using Java Reflection Concept)
2.Understand the dtd. there are two types of dtd available mapping dtd and configuration dtd
Mapping-dtd is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
configuration dtd is
<?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">
hibernate.cfg.xml is configuration file and Person.hbm.xml is Mapping File so change the dtd in Person.hbm.xml
it will run.
The error message says (buried in a big stack trace):
Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration"
This is because in your Person.hbm.xml file, you have
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
where you should probably have
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
This DOCTYPE has to match the root tag.
InvalidmappingException arise in some condition please to read carefully
we will use instead of id tag we use then this exception occur definitely.
In Pojo class you declare data member like "name" in database u declare "name" ok then in mapping file u write just in brief terms we can say that like whatever u declare in id tag name attribute value its corresponding there is no data member in pojo class then only one error arise InvalidMappingException .
SQLGrammarException arise when orthis column name not exact match to corresponding database filed.
I also got this error message. But in my case the class name was wrong. Add correct package and class name according to bellow example.
<class name="com.project.Question" table="question">