2

我得到了例外

play.api.UnexpectedException: Unexpected exception [PersistenceException: No Persistence provider for EntityManager named defaultPersistenceUnit]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anonfun$1.apply(ApplicationProvider.scala:134) ~[play_2.9.1.jar:2.0.1]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anonfun$1.apply(ApplicationProvider.scala:112) ~[play_2.9.1.jar:2.0.1]
at scala.Option.map(Option.scala:133) ~[scala-library.jar:0.11.2]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3.apply(ApplicationProvider.scala:112) ~[play_2.9.1.jar:2.0.1]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3.apply(ApplicationProvider.scala:110) ~[play_2.9.1.jar:2.0.1]
at scala.Either$RightProjection.flatMap(Either.scala:277) ~[scala-library.jar:0.11.2]
at play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:110) ~[play_2.9.1.jar:2.0.1]
at play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:110) ~[play_2.9.1.jar:2.0.1]
at akka.dispatch.Future$$anon$3.liftedTree1$1(Future.scala:195) ~[akka-actor.jar:2.0.1]
at akka.dispatch.Future$$anon$3.run(Future.scala:194) ~[akka-actor.jar:2.0.1]
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:83) ~[akka-actor.jar:2.0.1]
at akka.jsr166y.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1381) ~[akka-actor.jar:2.0.1]
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) ~[akka-actor.jar:2.0.1]
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:974) ~[akka-actor.jar:2.0.1]
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1478) ~[akka-actor.jar:2.0.1]
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) ~[akka-actor.jar:2.0.1]
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named defaultPersistenceUnit
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final]
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) ~[hibernate-jpa-2.0-api.jar:1.0.1.Final]
at play.db.jpa.JPAPlugin.onStart(JPAPlugin.java:35) ~[play_2.9.1.jar:2.0.1]
at play.api.Play$$anonfun$start$1.apply(Play.scala:60) ~[play_2.9.1.jar:2.0.1]
at play.api.Play$$anonfun$start$1.apply(Play.scala:60) ~[play_2.9.1.jar:2.0.1]
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) ~[scala-library.jar:0.11.2]
at scala.collection.immutable.List.foreach(List.scala:45) ~[scala-library.jar:0.11.2]
at play.api.Play$.start(Play.scala:60) ~[play_2.9.1.jar:2.0.1]
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anonfun$1.apply(ApplicationProvider.scala:125) ~[play_2.9.1.jar:2.0.1]
... 15 common frames omitted

我在文件夹 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-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes> 
    <properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
    </properties>
</persistence-unit>
</persistence>

最后是我的 application.conf

#Database Configuration
db.default.driver=net.sourceforge.jtds.jdbc.Driver
db.default.url="jdbc:jtds:sqlserver://server3;DatabaseName=SANDBOX"
db.default.user=private
db.default.pass=private
db.default.jndiName=DefaultDS
# JPA Configuration
jpa.default=defaultPersistenceUnit

我一直在疯狂地试图找出问题所在。任何见解或建议将不胜感激。

4

1 回答 1

0

您需要在persistence-unit节点下添加以下行:

<non-jta-data-source>DefaultDS</non-jta-data-source>
于 2012-12-24T13:17:47.563 回答