Skip to content
Jens Jäger

JPA configuration for play framework

This post is part of the archive. It was written years ago, so some of the tools, versions and links may be outdated.

In my current play project we decided to use hibernate as JPA implementation.

Here is the configuration we use:

Dependencies in project/Build.scala

  val appDependencies = Seq(
    javaCore,
    javaJdbc,
    javaJpa,
    "org.hibernate" % "hibernate-entitymanager" % "4.2.7.Final"
  )

Database configuration in conf/application.conf

# Database configuration
# ~~~~~
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:file:data/db"
db.default.user=sa
db.default.password=""
db.default.jndiName=DefaultDS

jpa.default=defaultPersistenceUnit

Persistence unit in conf/META-INF/persistence.xml

<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_2_0.xsd"
             version="2.0">

    </persistence><persistence -unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non -jta-data-source>DefaultDS</non>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"></property>
            <property name="hibernate.hbm2ddl.auto" value="update"></property>
            <property name="hibernate.show_sql" value="true"></property>
            <property name="hibernate.format_sql" value="true"></property>
            <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultComponentSafeNamingStrategy"></property>
        </properties>
    </persistence>

2 comments

  1. Hi!

    We run a play 1.x application using jpa/hibernate. We think about migration to 2.x sometime next year.
    It would be nice if you keep posting about your experiences with play 2.x and jpa (specially in contrast to the jpa implemenation in play 1.x, what are the main differences)

    Thanks!

    M.

  2. JensAuthor

    Hi M.,

    thanks for your commit. I will try to find some time to blog more about the topic.

    Jens

Comments are closed. Join the conversation on LinkedIn.