Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manual/working/javaGuide/main/sql/JavaJPA.md #1250

Open
garbagetown opened this issue Feb 8, 2016 · 0 comments
Open

manual/working/javaGuide/main/sql/JavaJPA.md #1250

garbagetown opened this issue Feb 8, 2016 · 0 comments
Milestone

Comments

@garbagetown
Copy link
Member

--- /Users/garbagetown/Desktop/2.2.0/manual/working/javaGuide/main/sql/JavaJPA.md   2016-02-07 23:19:03.000000000 +0900
+++ //Users/garbagetown/Desktop/2.4.x/manual/working/javaGuide/main/sql/JavaJPA.md  2016-02-07 23:19:30.000000000 +0900
@@ -1,3 +1,4 @@
+<!--- Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com> -->
 # Integrating with JPA

 ## Adding dependencies to your project
@@ -7,15 +8,15 @@
 There is no built-in JPA implementation in Play; you can choose any available implementation. For example, to use Hibernate, just add the dependency to your project:

 '''
-val appDependencies = Seq(
+libraryDependencies ++= Seq(
   javaJpa,
-  "org.hibernate" % "hibernate-entitymanager" % "3.6.9.Final" // replace by your jpa implementation
+  "org.hibernate" % "hibernate-entitymanager" % "4.3.9.Final" // replace by your jpa implementation
 )
 '''

 ## Exposing the datasource through JNDI

-JPA requires the datasource to be accessible via JNDI. You can expose any Play-managed datasource via JDNI by adding this configuration in `conf/application.conf`:
+JPA requires the datasource to be accessible via JNDI. You can expose any Play-managed datasource via JNDI by adding this configuration in `conf/application.conf`:

 '''
 db.default.driver=org.h2.Driver
@@ -30,13 +31,13 @@
 Here is a sample configuration file to use with Hibernate:

 '''
-<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+<persistence xmlns="http://xmlns.jcp.org/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">
+             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
+             version="2.1">

     <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
-        <provider>org.hibernate.ejb.HibernatePersistence</provider>
+        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
         <non-jta-data-source>DefaultDS</non-jta-data-source>
         <properties>
             <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
@@ -49,9 +50,18 @@
 Finally you have to tell Play, which persistent unit should be used by your JPA provider. This is done by the `jpa.default` property in your `application.conf`.

 '''
-jpa.default=defaultPerstistenceUnit
+jpa.default=defaultPersistenceUnit
 '''

+## Deploying Play with JPA
+
+Running Play in development mode while using JPA will work fine, but in order to deploy the application you will need to add this to your `build.sbt` file.
+
+@[](code/jpa.sbt)
+
+Since Play 2.4 the contents of the `conf` directory are added to the classpath by default. This option will disable that behavior and allow a JPA application to be deployed. Note that the content of conf directory will still be available in the classpath due to it being inclued in the applications jar file.
+
+
 ## Annotating JPA actions with `@Transactional`

 Every JPA call must be done in a transaction so, to enable JPA for a particular action, annotate it with `@play.db.jpa.Transactional`. This will compose your action method with a JPA `Action` that manages the transaction for you:
@@ -63,7 +73,7 @@
 }
 '''

-If your action perfoms only queries, you can set the `readOnly` attribute to `true`:
+If your action runs only queries, you can set the `readOnly` attribute to `true`:

 '''
 @Transactional(readOnly=true)
@@ -82,4 +92,6 @@
 }
 '''

-> **Next:** [[Using the cache | JavaCache]]
+## Enabling Play database evolutions
+
+Read [[Evolutions]] to find out what Play database evolutions are useful for, and follow the setup instructions for using it.
\ No newline at end of file

@garbagetown garbagetown added this to the 2.4.x milestone Feb 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants