java - Maven Hibernate 实体类未找到异常

标签 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) 在 sun.reflect.NativeMethodAccessorImpl.invoke0( native 方法) 在 sun.reflect.NativeMethodAccessorImpl.invoke(来源未知) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(来源未知) 在 java.lang.reflect.Method.invoke(来源未知)

最佳答案

您可能需要告诉 Maven 包含这些文件。在 pom.xml 中尝试类似的操作:

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

关于java - Maven Hibernate 实体类未找到异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31676014/

相关文章:

java - 如何从 Java 运行 Maven?

java - Hibernate中 "insertable=false"和 "transient"的区别

java - 根据枚举验证 JSON 字段

java - 为什么当我添加productimage代码和 "productname"ProductNAME时不支持 "NULL not allowed for column "; SQL语句:"

java - hibernate 错误:- Error during managed flush [Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1]

java - 当我的项目中没有任何实体时,如何将 native 查询映射到 POJO?

java - Maven 2.2.1 附加测试。问题-Dmaven.test.skip=true

spring - 连接到本地主机 :5432 refused after docker run when port 5432 is clearly open and listening?

java - 轴突迁移从 2.4 到 3.1

java - 扩展一个扩展 Hadoop 的 Mapper 的类