Java “线程中的异常”;“主要”;org.hibernate.MappingException:未知实体:bitronix.examples.hibernate.entities.User

Java “线程中的异常”;“主要”;org.hibernate.MappingException:未知实体:bitronix.examples.hibernate.entities.User,java,hibernate,hibernate-mapping,hibernate-4.x,Java,Hibernate,Hibernate Mapping,Hibernate 4.x,我在eclipse控制台上遇到以下异常 Exception in thread "main" org.hibernate.MappingException: Unknown entity: bitronix.examples.hibernate.entities.User 我的hibernate.cfg.xml类似于: <hibernate-configuration> <session-factory> <property name="h

我在eclipse控制台上遇到以下异常

Exception in thread "main" org.hibernate.MappingException: Unknown entity: bitronix.examples.hibernate.entities.User
我的hibernate.cfg.xml类似于:

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.password">postgres</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/bitronixH4</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.connection.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.hbm2ddl.auto">create</property>
        <mapping resource="bitronix/examples/hibernate/entities/User.hbm.xml" />
    </session-factory>
</hibernate-configuration>

任何建议或帮助都将不胜感激

编辑:My User.java是这样的

public class User {
private Integer id;
private String name;
//getters and setters
}
<hibernate-mapping >
    <class name="bitronix.examples.hibernate.entities.User" table="test_user" >
        <id name="id" type="int">
            <column name="id" />
            <generator class="identity" />
        </id>
        <property name="name" type="string">
            <column name="name" />
        </property>
    </class>
</hibernate-mapping>
我的User.hbm.xml是这样的

public class User {
private Integer id;
private String name;
//getters and setters
}
<hibernate-mapping >
    <class name="bitronix.examples.hibernate.entities.User" table="test_user" >
        <id name="id" type="int">
            <column name="id" />
            <generator class="identity" />
        </id>
        <property name="name" type="string">
            <column name="name" />
        </property>
    </class>
</hibernate-mapping>

显然,配置代码存在问题。创建
配置
两次

照办

SessionFactory sf1 = new Configuration().configure().buildSessionFactory();
我知道,它在Hibernate4中被弃用了。但是对于Hibernate5来说,这是一个好方法。这种Hibernate4方法不适用于Hibernate5


向我们展示您用来初始化Hibernate的Java代码。除了上面发布的Test.Java类之外,我没有其他Java代码。现在我不得不承认我在生活中犯了这么愚蠢的错误。@BhushanPatil每个人都可能在配置上犯错误。Hibernate有一个非常不方便的API和一个不清楚的文档。尽量少写代码。例如,这里有很多人使用了很多不必要的注释。