【问题标题】:Java Hibernate invalid mapping exceptionJava Hibernate 无效映射异常
【发布时间】:2018-05-10 17:13:27
【问题描述】:

我的代码在 xml 映射中运行良好,然后我更改为注释,但出现此错误:

Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML

这是我的 XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/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/hibernate1?useLegacyDatetimeCode=false&amp;serverTimezone=UTC</property>
        <property name="connection.username">hibernate1</property>
        <property name="connection.password">mypassword</property>
        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <property name="hibernate.show_sql">true</property>
        <mapping class="hibernate.Profesor" file="" jar="" package="" resource=""/>
        <mapping class="hibernate.Direccion" file="" jar="" package="" resource=""/>
    </session-factory>
</hibernate-configuration>

【问题讨论】:

    标签: java hibernate hibernate-annotations


    【解决方案1】:

    我能够让它为我工作,只更改 connection.urlconnection.usernameconnection.password

    // A SessionFactory is set up once for an application
    SessionFactory sessionFactory = new Configuration()
        .configure() // configures settings from hibernate.cfg.xml
        .buildSessionFactory();
    

    删除您的映射配置文件。也就是说,如果Profesor.hbm.xmlDireccion.hbm.xml 仍然存在,则删除它们。如果您使用注释,则不需要它们。 如果您使用的是 Maven,请确保您具有以下依赖项:

    另外,com.mysql.jdbc.Driver 已被弃用。使用com.mysql.cj.jdbc.Driver

    如果您发布异常的整个堆栈跟踪会更有帮助。

    【讨论】:

      猜你喜欢
      • 2012-03-11
      • 1970-01-01
      • 1970-01-01
      • 2011-05-18
      • 1970-01-01
      • 1970-01-01
      • 2017-02-18
      • 2018-02-24
      • 2020-04-01
      相关资源
      最近更新 更多