gpt4 book ai didi

java - Play Framework JPA - 找不到实体

转载 作者:行者123 更新时间:2023-12-02 13:40:17 25 4
gpt4 key购买 nike

我目前正在尝试将我的 Play 应用程序作为已部署的应用程序运行。它有一个 JPA 集成,如果我在本地运行该应用程序,它可以正常工作。但如果我尝试在生产模式下运行,我当前会收到此错误:

Caused by: java.lang.IllegalArgumentException: Not an entity: class 
com.mm.entities.Message
at org.hibernate.jpa.internal.metamodel.MetamodelImpl.entity(MetamodelImpl.java:194)
at org.hibernate.jpa.criteria.QueryStructure.from(QueryStructure.java:124)
at org.hibernate.jpa.criteria.CriteriaQueryImpl.from(CriteriaQueryImpl.java:156)
at com.mm.helpers.QueryBuilder.<init>(QueryBuilder.java:24)
at com.mm.persistence.MessagePersistence.getByReceiver(MessagePersistence.java:49)
at com.mm.controllers.Messages.getMessageByReceiver(Messages.java:47)
at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(Routes.scala:91)
at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(Routes.scala:91)
at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:157)
at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:156)

有人知道它来自哪里吗?我的 persistence.xml 中的持久性单元如下所示:

<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>MMChat</non-jta-data-source>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>

最佳答案

对于生产模式,每个与数据库实体相关的类都应使用完整的包名称添加到 persistence.xml 中。 DB实体相关类是实体、可嵌入类或属性转换器类中的任何一个。在你的情况下,这应该是这样的:

<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>MMChat</non-jta-data-source>
<class>com.mm.entities.Message</class>
<properties>
...
</properties>
</persistence-unit>

关于java - Play Framework JPA - 找不到实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42770834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com