Hi.
My DB is a local instance of H2 database (
www.h2database.com).
I have configure hibernate to work with session context, my plan (and I need it) is to configure to use EntityManager context. But Im getting so much problems:
First: I have tried to use toplink:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="OfflineSystemPU" transaction-type="RESOURCE_LOCAL">
<class>br.gov.ba.cedasc.ols.model.Auditoria</class>
<class>br.gov.ba.cedasc.ols.model.Procedimento</class>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="toplink.jdbc.user" value="sa"/>
<property name="toplink.jdbc.password" value="cliente"/>
<property name="toplink.jdbc.url" value="jdbc:h2:~/db/offline"/>
<property name="toplink.jdbc.driver" value="org.h2.Driver"/>
<property name="toplink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
Hibernate connect to DB, but it´s give warning because don´t see a valid dialect for H2 database.
And hibernate try to create tables and sequence but it´s fail.
My second attempts was to build like a hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="OfflineSystemPU" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<class>br.gov.ba.cedasc.ols.model.Auditoria</class>
<class>br.gov.ba.cedasc.ols.model.Procedimento</class>
<properties>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value="cliente"/>
<property name="hibernate.connection.url" value="jdbc:h2:~/db/offline"/>
<property name="hibernate.connection.driver_class" value="org.h2.Drive"/>
<property name="hibernate.hbm2dll.auto" value="create"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
I just want one example that hibernate can connect to H2 database thru JPA EntityManager and create some DDL.
I cannot use session context anymore.
Thanks all for patience.