Я получаю следующее исключение на затмение консолиИсключение в потоке «основного» 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();
}
}
Любое предложение или помощь приветствуются.
EDIT: Мой 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>
Покажите нам код Java, который вы используете для инициализации Hibernate. –
У меня нет кода Java, кроме класса Test.java, который у меня есть выше. –