Hello,
I'm trying to obtain a SessionFactory with hibernate 4.3.10 but with a persistence.xml configuration file.
I've read that the AnnotationConfiguration class used to read persistence.xml is deprecated and all features have been included in Configuration.class
Here is the code I use :
Code:
Configuration configuration = new Configuration()
.addFile("src/test/resources/META-INF/persistence.xml");
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.openSession();
But this produce a
Exception in thread "main" org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not setWhile my persistence.xml contains that dialect :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="jpacourse" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>model.Customer</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:tcp://localhost/d:/tmp/database" />
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="none" />
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
</properties>
</persistence-unit>
</persistence>
Does anybody know how to obtain a correct Configuration instance from a persistence.xml
I really don't want to configure a persistence.xml and maintain in parallel a hibernate.cfg.xml but the persistence.xml is more important to me.
I don't want to use Persistence class to obtain the SessionFactory because it's a demonstration of the different API for a Hibernate course.
Thanks.