首页 > 解决方案 > 播放 2.6 Inject JPAApi error "No Persistence provider for EntityManager named defaultPersistenceUnit"

问题描述

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

控制器.PublicController.java

public class PublicController extends Controller {

    @Inject
    public PublicController(JPAApi apaApi) {}

}

构建.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>

应用程序.conf

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

我已经检查了所有,但我不明白我做错了什么。请帮忙。谢谢!

标签: playframework-2.6

解决方案


解决了。模型链接有问题,OneToMany 和 ManyToOne 链接不正确


推荐阅读