未找到Maven Hibernate实体类异常

时间:2015-07-28 12:14:22

标签: java hibernate maven

即使我知道这是最常见的问题之一,我也无法独自解决,所以我决定要问它。

Hibernate无法找到我的.hbm.xml文件或实体类。这是我的文件结构:enter image description here

这是hbm文件之一:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jul 24, 2015 9:36:20 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="org.kelime.dbModel.Kelime" table="kelime" catalog="distributedproject">
        <id name="kelime" type="string">
            <column name="Kelime" length="50" />
            <generator class="assigned" />
        </id>
    </class>
</hibernate-mapping>

这是错误: org.hibernate.MappingNotFoundException:找不到资源:org.kelime.dbModel.Kelime.hbm.xml     在org.hibernate.cfg.Configuration.addResource(Configuration.java:724)     在org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2102)     在org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2074)     在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2054)     在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2007)     在org.hibernate.cfg.Configuration.configure(Configuration.java:1922)     在org.kelime.HibernateUtils.HibernateUtils。(HibernateUtils.java:15)     在org.kelime.rest.AccountController.registerNewUser(AccountController.java:26)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)     在java.lang.reflect.Method.invoke(未知来源)

2 个答案:

答案 0 :(得分:1)

您可能需要告诉maven包含这些文件。在pom.xml中尝试这样的事情:

<build>
    <resources>
        <resource>
            <directory>src/main/java/</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
    </resources>
</build>

答案 1 :(得分:0)

我和我的朋友已经解决了这个问题..我不知道为什么但是由于某种原因它只适用于这种编码方式:

Configuration configuration = new Configuration(); configuration.addResource("./org/kelime/dbModel/Kelime.hbm.xml"); configuration.addResource("./org/kelime/dbModel/Kullanici.hbm.xml");