org.hibernate.InvalidMappingException:Could not parse mapping document from resource com/lara/Person.hbm.xml

前端 未结 4 750
时光取名叫无心
时光取名叫无心 2020-12-12 01:35
Exception in thread \"main\" org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/lara/Person.hbm.xml
    at org.hibernate.cfg.C         


        
相关标签:
4条回答
  • 2020-12-12 01:57

    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.

    0 讨论(0)
  • 2020-12-12 02:01

    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.

    0 讨论(0)
  • 2020-12-12 02:12

    InvalidmappingException arise in some condition please to read carefully

    1. we will use instead of id tag we use then this exception occur definitely.

    2. 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 .

    3. SQLGrammarException arise when orthis column name not exact match to corresponding database filed.

    0 讨论(0)
  • 2020-12-12 02:13

    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">
    
    0 讨论(0)
提交回复
热议问题