如何使用class属性在hibernate中映射类?

时间:2015-06-03 10:43:33

标签: java hibernate maven

我的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>

1 个答案:

答案 0 :(得分:2)

我应该补充一下:

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"/>