Previous: Object Model Up: Tutorial Next: Test Data

In order to use JPA, we need a persistence.xml. We have to put it into the src/main/resources/META-INF folder, which we have to create previously. We want Hibernate to use HSQLDB and create the schema for us, so our persistence.xml looks like this:

    
<persistence 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"
             version="1.0">

  <persistence-unit name="contacts" transaction-type="RESOURCE_LOCAL">

    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <class>net.sf.jpasecurity.contacts.model.User</class>
    <class>net.sf.jpasecurity.contacts.model.Contact</class>

    <properties>
      <property name="hibernate.hbm2ddl.auto" value="create-drop" />
      <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
      <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
      <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:contacts" />
      <property name="hibernate.connection.username" value="sa" />
      <property name="hibernate.connection.password" value="" />
    </properties>

  </persistence-unit>

</persistence>
    
  


Previous: Object Model Up: Tutorial Next: Test Data