Hi. I am trying to set up a basic example app with play 2.4.6 + jpa +
hibernate and in memory database. I followed the docs but I am getting
this error when trying to perist an entity:
---
[PersistenceException: org.hibernate.exception.SQLGrammarException: could
not prepare statement]
---
In the stacktrace I can read this:
---
Caused by: org.h2.jdbc.JdbcSQLException: Tabla "ITEM" no encontrada
Table "ITEM" not found; SQL statement:
insert into Item (id, name) values (null, ?) [42102-187]
---
What could be the problem here? I think it should apply an initial
evolution script creating the "ITEM" table when starting the app, but I
get no evolutions script message.
I come from a Play 1 background, where working with a database is a piece
of cake. Now I feel pretty lost as I have never had to deal with
persistence.xml or EntityManager. Could you give me a hand? Below is my
source code.
Regards,
Juan Carlos
This is my action:
---
@Transactional
public Result index() {
Item i = new Item();
i.name = "item1";
JPA.em().persist(i);
return ok(index.render("Your new application is ready."));
}
---
This is my model class at models.Item.java:
---
@Entity
public class Item {
@Id
@GeneratedValue
public Long id;
public String name;
}
---
This is my persistence.xml file:
---
<persistence xmlns="
http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
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="default" transaction-type="RESOURCE_LOCAL">
<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"/>
</properties>
</persistence-unit>
</persistence>
---
This are my db related configurations:
---
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.jndiName=DefaultDS
jpa.default=default
---
This is my build.sbt file:
---
name := """hibernated"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
javaJpa,
"org.hibernate" % "hibernate-entitymanager" % "4.3.11.Final",
evolutions
)
routesGenerator := InjectedRoutesGenerator
---
This is my plugins.sbt file:
---
addSbtPlugin("
com.typesafe.play" % "sbt-plugin" % "2.4.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
---