无法修改休眠设置

时间:2014-10-15 12:56:35

标签: java windows hibernate

我创建了 hibernate.cfg.xml UserDataFromDb.hbm.xml ,并尝试将其放在正确的位置。第一次出现像"Cannot find hibernate.cfg.xml"这样的异常,但经过几次更换后找到了正确的位置。新的例外是(除了许多其他痕迹之外):

  

引起:org.hibernate.HibernateException:未找到枚举类
   引起:java.lang.ClassNotFoundException:net.codejava.hibernate.Gender

没关系,因为我忘了更改教程示例代码并打印我的班级名称。我已经解决了这个问题,因此,现在没有提及 UserDataFromDb.hbm.xml 中的类Gender。问题肯定是一样的。

我已将 UserDataFromDb.hbm.xml hibernate.cfg.xml 替换为桌面,甚至将其重命名。因此,我的计算机上没有 UserDataFromDb.hbm.xml hibernate.cfg.xml 文件(而不是它们 - UserData11FromDb.hbm.xml和hiber111nate。桌面上的cfg.xml)。例外情况仍然相同:

  

引起:org.hibernate.HibernateException:未找到枚举类
   引起:java.lang.ClassNotFoundException:net.codejava.hibernate.Gender

虽然在计算机上既没有Gender类,也没有配置和映射文件。

重新启动计算机无效。 OS Windows 7,Hibernate 4.3.6

配置文件:

`

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">
            org.hibernate.dialect.MySQLDialect
        </property>
        <property name="hibernate.connection.driver_class">
            com.mysql.jdbc.Driver
        </property>

        <!-- Assume test is the database name -->
        <property name="hibernate.connection.url">
            jdbc:mysql://localhost/abusefinder
        </property>
        <property name="hibernate.connection.username">
            root
        </property>
        <property name="hibernate.connection.password">

        </property>

        <!-- List of XML mapping files -->
        <mapping resource="UserDataFromDb.hbm.xml" />

    </session-factory>
</hibernate-configuration>

映射:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 

<hibernate-mapping>
    <class name="UserDataFromDb" table="user_history">
        <id name="id" type="int" column="id">
            <generator class="native"/>
        </id>
        <list name="operations" cascade="all">
            <key column="user_id"/>
            <list-index column="idx"/>
            <one-to-many class="Operation"/>
        </list>
        <property name="maxOpersPerWeek" column="max_opers_per_week" type="int"/>
        <property name="currentOpersPerWeek" column="current_opers_per_week" type="int"/>
        <property name="lastWeekFirstOperationTime" column="last_week_first_operation_time"     type="long"/>
        <property name="addTotal" column="add_total" type="long"/>
        <property name="getTotal" column="get_total" type="long"/>
        <property name="addOpers" column="add_opers" type="int"/>
        <property name="getOpers" column="get_opers" type="int"/>
    </class>


    <class name="Operation" table="operations">
        <id name="operId" type="int" column="oper_id">
            <generator class="native"/>
        </id>
        <property name="userId" column="user_id" type="int"/>
        <property name="sum" column="sum" type="long"/>
        <property name="time" column="time" type="long"/>
        <property name="type" column="type">
            <type name="org.hibernate.type.EnumType">
                <param name="enumClass">databaseaccess.Type</param>
                <param name="useNamed">true</param>
            </type>
        </property>
    </class>
</hibernate-mapping>

1 个答案:

答案 0 :(得分:0)

项目 - &gt;清洁 项目 - &gt;构建