Spring 3项目中的Hibernate基本配置 - 未找到类异常

时间:2013-05-02 18:40:53

标签: java mysql spring hibernate

我正在尝试在现有Hibernate 3.6 + Spring 3 MVC项目中设置Spring 3 security。尽管如此,我仍然会在java.lang.ClassNotFoundException课程中HibernateUtil获得return new Configuration().configure().buildSessionFactory();

我的项目结构如下:

enter image description here

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<!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="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">password</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3049/test</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="show_sql">true</property>
        <mapping resource="./DBUser.hbm.xml"></mapping>
    </session-factory>
</hibernate-configuration>

DBUser.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="../src/main/java/user/DBUser" table="DBUSER">
        <id name="userId" type="int">
            <column name="USER_ID" precision="5" scale="0" />
            <generator class="assigned" />
        </id>
        <property name="username" type="string">
            <column name="USERNAME" length="20" not-null="true" />
        </property>
        <property name="createdBy" type="string">
            <column name="CREATED_BY" length="20" not-null="true" />
        </property>
        <property name="createdDate" type="date">
            <column name="CREATED_DATE" length="7" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

pom.xml文件的相关部分:

<!-- Hibernate + MySQL -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.9</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.6.3.Final</version>
        </dependency>
编辑:我已粘贴here the stack trace。把它放在这里太长了,因为这会让这个帖子感到困惑。

我真的很高兴,如果有人可以帮我设置这个东西,因为我不知道,为什么它找不到那个课。

2 个答案:

答案 0 :(得分:1)

您的类名应该是DBUser.hbm.xml中Hibernate POJO的包路径,例如:

user/DBUser

您的地图资源在路径中不需要./

答案 1 :(得分:1)

看起来你错过了javaassist库。下载javaassist jar并将其添加到类路径中。