播放2.6注入JPAApi错误“没有为EntityManager指定defaultPersistenceUnit的持久性提供程序”

时间:2018-06-05 13:52:36

标签: playframework-2.6

我在我的2.6.15应用程序中使用Ebean。但我没有在ebean中找到“getSingleResult”函数。我尝试使用JPAApi。当控制器尝试注入JPAApi时,我收到错误No Persistence provider for EntityManager named defaultPersistenceUnit

controllers.PublicController.java

public class PublicController extends Controller {

    @Inject
    public PublicController(JPAApi apaApi) {}

}

build.sbt

lazy val server = (project in file("."))
  .enablePlugins(BuildInfoPlugin, PlayJava, PlayEbean)
  .settings(
    libraryDependencies += guice,
    libraryDependencies ++= Seq(
      ...
      javaJpa,
      "org.hibernate" % "hibernate-entitymanager" % "5.3.1.Final"
  ),
  fork in run := true
)

/conf/META-INF/persistence.xml

<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="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <non-jta-data-source>DefaultDS</non-jta-data-source>
    <properties>
      ...
    </properties>
  </persistence-unit>

</persistence>

application.conf

db {
  default {
    driver = com.mysql.jdbc.Driver
    jndiName = DefaultDS
    url = "***"
    username = "***"
    password = "***"
    hikaricp {
      minimumIdle = ${fixedConnectionPool}
      maximumPoolSize = ${fixedConnectionPool}
    }
  }
}
jpa.default = defaultPersistenceUnit

我已经检查了所有但我无法理解我做错了什么。请帮忙。谢谢!

1 个答案:

答案 0 :(得分:0)

已解决。是链接模型的问题,是不正确的OneToMany和ManyToOne链接