【问题标题】:how to map classes in hibernate using the class attribute?如何使用类属性在休眠中映射类?
【发布时间】:2015-06-03 10:43:33
【问题描述】:

我的 maven 项目有问题 点击下面的链接查看 我将此添加到我的 hibernate.cfg 但没有工作

<mapping package="com.redpass.entities"/>
<mapping class="com.redpass.entities.MyReference"/>

console error
Project Explorer

hibernate.cfg.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>
        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/avocatbd</property>
        <property name="connection.username">root</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- <mapping package="com.redpass.entities"/>
        <mapping class="com.redpass.entities.MyReference"/> -->
    </session-factory>
</hibernate-configuration>

【问题讨论】:

  • 您能否添加更多详细信息,特别是您的 hibernate.cfg.xml
  • 我添加了.cfg文件并点击上面的控制台错误和项目资源管理器

标签: java hibernate maven


【解决方案1】:

我应该添加这个:

configuration.configure("hibernate.cfg.xml");
        return configuration
                .buildSessionFactory(new StandardServiceRegistryBuilder()
                        .applySettings(configuration.getProperties())
                        .build());

到我的 HibernateUtil 类,告诉我们要使用 hibernate.cfg.xml 文件进行配置并像这样映射类:

<mapping class="com.redpass.entities.Partie"/>
<mapping class="com.redpass.entities.Societe"/>

【讨论】:

  • 请编辑您的问题,不要将其发布为答案。
猜你喜欢
  • 2017-04-09
  • 1970-01-01
  • 2017-11-14
  • 1970-01-01
  • 2013-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多