Port of schuchert.wikispaces.com


JPA_Tutorial_Project_Setup

JPA_Tutorial_Project_Setup

Create Java Project

Next we need to create a Java project. We’ll keep the source separate from the bin directory:

Create folders and packages

Add Required Libraries

We now need to add two libraries. Note that these steps assume you’ve already worked through the first tutorial and are working in the same workspace. If you, you’ll need to create user libraries. Review Creating User Libraries.

If you’d like some background information on JUnit, please go here.

Configure Persistence Unit


title: JpaPersistenceUnit —

We now need to create the Persistent Unit definition. We are going to create a file called persistence.xml in the src/META-INF directory with the following contents:

persistence.xml

<persistence>
    <persistence-unit name="examplePersistenceUnit" 
                      transaction-type="RESOURCE_LOCAL">
        <properties>
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.format_sql" value="false" />

            <property name="hibernate.connection.driver_class" 
                      value="org.hsqldb.jdbcDriver" />
            <property name="hibernate.connection.url" 
                      value="jdbc:hsqldb:mem:mem:aname" />
            <property name="hibernate.connection.username" value="sa" />

            <property name="hibernate.dialect" 
                      value="org.hibernate.dialect.HSQLDialect" />
            <property name="hibernate.hbm2ddl.auto" value="create" />
        </properties>
    </persistence-unit>
</persistence>

The Steps

  • Expand your ****
  • Select the src directory
  • Find the src/META-INF directory (if one does not exist, right-click, select New:Folder, enter META-INF and press enter)
  • Right click the src/META-INF, select new:File.
  • Enter persistence.xml for the name and press “OK” (Note: all lowercase. It won’t make a difference on Windows XP but it will on Unix.)
  • Copy the contents (above) into the file and save it

Comments

" Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.