获取“线程“主”中的异常” java.lang.IllegalArgumentException:未知实体:<entityclass>”

时间:2019-01-09 11:29:13

标签: java hibernate oracle12c

我创建了一个简单的休眠应用程序,并在运行时遇到上述异常(我使用的是hibernate 5.4.0.Final版本)。如果我使用版本4.3.5.Final而不是5.4.0.Final

,一切正常

尝试过How to get rid of 'java.lang.IllegalArgumentException: Unknown entity' while running a simple hibernate app?,对我没有帮助。

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="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@192.168.0.998:1522:TEST</property>
        <property name="connection.username">test</property>
        <property name="connection.password">test</property>
        <property name="hbm2ddl.auto">update</property>
        <property name="show_sql">true</property>

        <mapping class="com.mahipal.model.WsdlMst"/>

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

踪迹:

Exception in thread "main"
java.lang.IllegalArgumentException: Unknown entity: com.mahipal.model.WsdlMst
    at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:807)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:788)
    at com.mahipal.test.Test.main(Test.java:56)

1 个答案:

答案 0 :(得分:0)

检查必须定义实体类的Hibernate配置文件:

例如

或者您必须使用以下方式将类显式添加到配置中

例如 configuration.addClass(annotations.Users.class) 读取映射作为应用程序resourceName addResource用于以声明方式添加hbml.xml文件 configuration.addResource(“ myFile.hbm.xml”); //不是hibernateAnnotations.cfg.xml