playframework-2.6 - 播放 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
我已经检查了所有,但我不明白我做错了什么。请帮忙。谢谢!
解决方案
解决了。模型链接有问题,OneToMany 和 ManyToOne 链接不正确
推荐阅读
- php - Laravel - 在 Jobs 中使用图像干预。图像ttfbbox错误
- r - readr::type_convert 弄乱了时间列
- linux - 带有 Qt 5.12 QSocketNotifier 的 ZeroMQ 只触发一次
- c# - 尽管用户具有正确的角色,但在控制器方法上使用 Authorize 注释仍显示“访问被拒绝”
- java - 使用 1.HttpURLConnection.setRequestProperty 和 2. 使用 CURL 将 b/w http 标头值设置为 null 有什么区别?
- mongodb - mongodb找到key过大的文档
- gulp - 如何调整我的 gulp 静态资产修订以与 ServiceWorkers 一起使用?
- hibernate - 我如何通过使用 Guava 来使用休眠 2 级缓存
- tabulator - 需要有关在制表器上加载和保存数据的建议
- ios - Objective-C/Xcode 状态栏颜色与导航栏颜色相同