【问题标题】:Play 2.6 Inject JPAApi error "No Persistence provider for EntityManager named defaultPersistenceUnit"播放 2.6 Inject JPAApi error "No Persistence provider for EntityManager named defaultPersistenceUnit"
【发布时间】:2018-08-29 13:40:37
【问题描述】:

我在 play 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

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

【问题讨论】:

    标签: playframework-2.6


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-24
      • 2016-04-11
      • 1970-01-01
      • 2014-09-30
      • 2023-02-26
      • 1970-01-01
      相关资源
      最近更新 更多