7.2. Configure Hibernate

JPA Objects (currently) uses Hibernate's native configuration mechanism, hibernate.cfg.xml, to specify the location of the database. Before you wade in, you can confirm the settings and that you have connectivity using the very simple org.starobjects.jpa.tools.Ping utility. This takes the following arguments:

When you're happy this is okay, then go ahead and update hibernate.cfg.xml.

<?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>
    <!--  debugging -->
    <property name="show_sql">false</property>
    <property name="bytecode.use_reflection_optimizer">true</property>
    <property name="hibernate.query.substitutions">true 1, false 0</property>

    <property name="connection.driver_class">org.postgresql.Driver</property>
    <property name="connection.username">myapp</property>
    <property name="connection.password">myapp_pwd</property>
    <property name="connection.url">jdbc:postgresql://localhost/myapp_db</property>
    <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
  </session-factory>
</hibernate-configuration>

This file should reside in the root directory of the classpath (eg in src/main/resources). A good place for it is alongside your JPA repository implementations.