I'm trying to get a Play 2.2 project to work with Hibernate JPA and a PostgreSQL database. I did it before with Play 2.1.1, where it worked perfectly. I get the following error now:
play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: org/w3c/dom/ElementTraversal]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:152) ~[play_2.10.jar:2.2.0]
I have no idea where this comes from. My build.sbt looks like this:
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaJpa,
"org.apache.directory.api" % "apache-ldap-api" % "1.0.0-M14",
"postgresql" % "postgresql" % "9.1-901-1.jdbc4",
"org.hibernate" % "hibernate-core" % "4.2.3.Final",
"org.hibernate" % "hibernate-entitymanager" % "4.2.3.Final"
)
And my persistence.xml 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_2_0.xsd"
version="2.0">
<persistence-unit name="defaultPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
I haven't written any code yet, I just configured it.
I narrowed it further down by myself. It seams that it is caused a conflict caused by the org.apache.directory.api I'm using. It is working without this library. I get the following message from sbt:
But I have no idea how to solve this conflict.
Ok, figured it out by myself. It was indeed a problem with two versions of xml-apis. One coming from Play itself and one from the Apache Directory API. I changed the artefact in the build.sbt to and it is working now:
You said that you didn't write any code, so I decided to show you how I created new Play! 2.2 application using JPA and Postgresql. You can do the same and check the difference.
First I created new Play application with command:
Then I created persistence.xml file in testApp/conf/META-INF directory and fill it with content:
Added to my testApp/conf/application.conf:
I also created sample model class:
I started play app with command:
Then I was able to see working website under http: //localhost:9000/ address. I was also able to see new Table test in postgres test database.