Какие существенные изменения произошли в 5.1.0.Final, из-за которых могут не работать маппинги в hibernate.xfg.xml? С весией 4.3.11.Final всё работает нормально.
При попытке сохранить объект в БД получаю исключение:
Exception in thread "main" org.hibernate.MappingException: Unknown entity: test.hibernate.Book
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:776)
at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1533)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:682)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:674)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:669)
at test.hibernate.Main.main(Main.java:26)
main():// Configure Hibernate and build session factory
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
// Save a book object
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
Book book = new Book();
book.setName("qwerty");
session.save(book);
transaction.commit();
session.close();
hibernate.cfg.xml:<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2:mem:test_db</property>
<property name="connection.username"></property>
<property name="connection.password"></property>
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create-drop</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping class="test.hibernate.Book" />
</session-factory>
</hibernate-configuration>
test.hibernate.Book:import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "books")
public class Book {
@Id
@GeneratedValue
private int id;
@Column(nullable = false, length = 100, unique = true)
private String name;
// Getters & setters...
}