Reputation: 1480
I'm having problems when loading a mapping file from the hibernate.cfg.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<mapping resource="User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The mapping file is not getting loaded in the SessionFactory
Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.test.dto.User
but if i add the mapping manually in the Configuration
instance:
static {
Configuration config = new Configuration().configure().addResource("User.hbm.xml");
ServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
sessionFactory = config.buildSessionFactory(registry);
}
The mapping works correctly..., any suggestions??
Upvotes: 0
Views: 1279
Reputation: 19956
Looks like a problem is the same as here. You can't mix configurations with new Configuration().configure()
and config.buildSessionFactory(registry)
. You should do all configuration with StandardServiceRegistryBuilder
.
Something like this
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().
configure().build();
SessionFactory sessionFactory= new Configuration().buildSessionFactory(serviceRegistry);
Upvotes: 2