简体   繁体   English

hibernate.hbm.xml中的无效映射异常

[英]Invalid Mapping Exception in hibernate.hbm.xml

I am posting my hbm file with the cfg file along with my error log. 我正在将我的hbm文件与cfg文件以及错误日志一起发布。 I found my questions based on similar problems are tried out their solution too but still my error is not fading away. 我发现基于类似问题的问题也可以尝试解决,但我的错误并未消失。

log 日志

Initial SessionFactory creation   failed.org.hibernate.InvalidMappingException: Could not parse mapping document from resource net/viralpatel/hibernate/Employee.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at   net.viralpatel.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:18)
  at net.viralpatel.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:8)
at net.viralpatel.hibernate.Main.main(Main.java:13)
 Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource net/viralpatel/hibernate/Employee.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1584)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1552)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1531)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1505)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
at net.viralpatel.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:14)
... 2 more
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:508)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 9 more
Caused by: org.dom4j.DocumentException: Error on line 9 of document  : The element type "generator" must be terminated by the matching end-tag "</generator>". Nested exception: The element type "generator" must be terminated by the matching end-tag "</generator>".
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)
... 10 more

Employee.hbm.xml Employee.hbm.xml

 <?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">
 <hibernate-mapping>
<class name="Employee" table="EMPLOYEE" >
    <id name="employeeId" column="EMPLOYEE_ID">
       <generator class="native"> 
    </id>
    <one-to-one name="employeeDetail" class="net.viralpatel.hibernate.EmployeeDetail"
        cascade="save-update"></one-to-one>

    <property name="firstname" column="firstname" />
    <property name="lastname" column="lastname" />
    <property name="birthDate" type="date" column="birth_date" />
    <property name="cellphone" column="cell_phone" />
    </class>

hibernate.cfg.xml hibernate.cfg.xml

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

    <hibernate-configuration>
    <session-factory>
    <property    name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property   name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
    <property name="connection.username">root</property>
    <property name="connection.password">tcs@1234</property>

    <property name="connection.pool_size">1</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="current_session_context_class">thread</property>
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    <property name="show_sql">true</property>
    <property name="hbm2ddl.auto">update</property>

    <mapping resource="net/viralpatel/hibernate/EmployeeDetail.hbm.xml"/>
    <mapping resource="net/viralpatel/hibernate/Employee.hbm.xml"/>

</session-factory>

In your Employee.hbm.xml you're not closing the generator tag. Employee.hbm.xml您没有关闭generator标签。 Replace 更换

<generator class="native">

by this 这样

<generator class="native"/> 

By looking at stack trace, you have not end the generator tag properly. 通过查看堆栈跟踪,您尚未正确结束generator标记。

Please change your employee.hbm.xml file to end the <generator> element properly. 请更改您的employee.hbm.xml文件以正确结束<generator>元素。

For Ex: It should be <generator class="native"/> 例如:应该是<generator class="native"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javax.persistence.PersistenceException:[PersistenceUnit:默认]无法解析命名的映射文件[hibernate.hbm.xml] - javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to resolve named mapping-file [hibernate.hbm.xml] 如何在hibernate.hbm.xml和users.java中自动添加列 - How to add column automatically in hibernate.hbm.xml and users.java 线程“main” org.hibernate.boot.MappingNotFoundException 中的异常:未找到映射(资源):allinone.hbm.xml:起源(allinone.hbm.xml) - Exception in thread "main" org.hibernate.boot.MappingNotFoundException: Mapping (RESOURCE) not found : allinone.hbm.xml : origin(allinone.hbm.xml) 映射hibernate hbm中的枚举? - Mapping an enum in hibernate hbm? 如何在Hibernate-Mapping XML(HBM 4.3)中使用JPA AttributeConverter? - How to use JPA AttributeConverter with Hibernate-Mapping XML (HBM 4.3)? 所有hibernate hbm.xml文件的一个映射文件夹 - one mapping folder for all hibernate hbm.xml files 线程“主” org.hibernate.InvalidMappingException中的异常:无法从资源userdata.hbm.xml中解析映射文档 - Exception in thread “main” org.hibernate.InvalidMappingException: Could not parse mapping document from resource userdata.hbm.xml Java Hibernate无效映射异常 - Java Hibernate invalid mapping exception 将休眠映射注释转换为hbm.xml文件 - Translate hibernate mapping anotations to hbm.xml file Hibernate-解析映射文件(.hbm.xml)时出现问题 - Hibernate - Problem in parsing mapping file (.hbm.xml)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM