Using persistence.xml and hibernate.cfg.xml
I am using JPA 2.0 + Hibernate 4.3.4
my persistence.xml:
<persistence-unit name="movie-unit">
<class>com.epam.rudenkov.controller.BookStore</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
</properties>
</persistence-unit>
my hibernate.cfg.xml:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">postgres</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres</property>
<property name="connection_pool_size">1</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
<mapping class="com.epam.rudenkov.model.Book"/>
</session-factory>
</hibernate-configuration>
I am currently getting an exception:
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: movie-unit] Unable to build EntityManagerFactory
Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set"}}
Questions:
- Do I need to install xmls for connection?
- If I don't need hibernate.cfg.xml, what does persistence.xml look like?
<persistence-unit name="movie-unit">
<class>com.epam.rudenkov.controller.BookStore</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">postgres</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/postgres</property>
<property name="connection_pool_size">1</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
<mapping class="com.epam.rudenkov.model.Book"/>
</properties></persistence-unit>
You can only do this with the persistence.xml file.
persistence.xml should look like the code above