我Eclipse控制檯異常線程 「main」 org.hibernate.MappingException:未知實體:bitronix.examples.hibernate.entities.User
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>
我Test.java類就像
package bitronix.examples.hibernate.entities;
public class Test {
public static void main(String[] args) {
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
SessionFactory sf1 = new Configuration()
.buildSessionFactory(serviceRegistry);
Session session = sf1.openSession();
session.beginTransaction();
User user = new User();
user.setName("rrr");
session.save(user);
session.getTransaction().commit();
}
}
任何建議或幫助表示讚賞。
編輯:我User.java是這樣
public class User {
private Integer id;
private String name;
//getters and setters
}
我User.hbm.xml是這樣
<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>
向我們展示你正在使用初始化Hibernate的Java代碼。 –
我沒有除Test.java類之外的任何Java代碼,我已在上面發帖。 –