/ / Výnimka vo vlákne "main" org.hibernate.MappingException: Neznáma entita: bitronix.examples.hibernate.entities.User - java, hibernate, hibernate-mapping, hibernate-4.x

Výnimku vo vlákne "main" org.hibernate.MappingException: neznáma entita: bitronix.examples.hibernate.entities.User - java, spánku, spánku-mapovanie, hibernate 4.x

Mám nasledujúcu výnimku na eclipse konzole

Exception in thread "main" org.hibernate.MappingException: Unknown entity: bitronix.examples.hibernate.entities.User

môj hibernate.cfg.xml je ako:

<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>

môj Test.java trieda je ako

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();
}
}

Moja štruktúra projektu

Akýkoľvek návrh alebo pomoc sú cenené.

EDIT: Môj User.java je takto

public class User {
private Integer id;
private String name;
//getters and setters
}

Môj User.hbm.xml je takto

<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>

odpovede:

1 pre odpoveď č. 1

Problém, samozrejme, s konfiguračným kódom. Vytvárate Configuration dvakrát.

Urob

SessionFactory sf1 = new Configuration().configure().buildSessionFactory();

Viem, že je zastaraný v režime Hibernate 4. Ale pre Hibernate 5 je to dobrý spôsob. Tento prístup Hibernate 4 nebude pracovať so zariadením Hibernate 5.

Hibernate 5: - org.hibernate.MappingException: Neznáma entita