当前位置: 首页 > 知识库问答 >
问题:

未生成DB架构:Play Framework 2.4 JPA Hibernate Heroku上的illegalargumentexception未知实体

王曜文
2023-03-14

我有一个困扰我几天的问题。我正在开发一个使用JPA的Play 2.4.0Java应用程序。本地(Foreman)一切正常,Hibernate自动创建架构,表等。

但是,Heroku上不会生成架构和表,我在访问应用程序(get test app/)时遇到此异常:

 @6naopal00 - Internal server error, for (GET) [/] ->
 at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36) [org.scala-lang.scala-library-2.11.
lay.api.UnexpectedException: Unexpected exception[IllegalArgumentException: Unknown entity: assets.EndUser]
 at scala.util.Try$.apply(Try.scala:191) [org.scala-lang.scala-library-2.11.6.jar:na]

 at scala.util.Failure$$anonfun$recover$1.apply(Try.scala:215) [org.scala-lang.scala-library-2.11.6.jar:na]
 at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:191) ~[com.typesafe.play.play_2.11-2.4
 at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324) [org.scala-lang.scala-library-2.11.6.jar:na]
 at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:261) ~[com.typesafe.p
 at scala.util.Failure.recover(Try.scala:215) [org.scala-lang.scala-library-2.11.6.jar:na]
 at play.api.GlobalSettings$class.onError(GlobalSettings.scala:179) [com.typesafe.play.play_2.11-2.4.2.jar:2.4.2]
 at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324) [org.scala-lang.scala-library-2.11.6.jar:na]
 at play.api.DefaultGlobal$.onError(GlobalSettings.scala:212) [com.typesafe.play.play_2.11-2.4.2.jar:2.4.2]
 at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [org.scala-lang.scala-library-2.11.6.jar:na]
 at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) [com.typesafe.akka.akka-actor_2.11-2.3.11.jar:na]
 at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:94) [com.typesafe.play.play_2.1
 at play.api.libs.iteratee.Execution$trampoline$.executeScheduled(Execution.scala:109) [com.typesafe.play.play-iterat
 at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [org.scala-lang.scala-library-2.
 at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$9$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHand

 at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:71) [com.typesafe.play.play-iteratees_2.11-2
 at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [org.scala-lang.scala-library-2.11.6.jar
 at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$14$$anon$3$$anon$1.invocation(HandlerInvok
 at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$9$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHand

 at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [org.scala-lang.scala-library-2.11.6.ja
 at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [org.scala-lang.scala-library-2
 at play.db.jpa.JPA.withTransaction(JPA.java:159) ~[com.typesafe.play.play-java-jpa_2.11-2.4.2.jar:2.4.2]
 at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248) [org.scala-lang.scala-library-2.11.6.
aused by: java.lang.IllegalArgumentException: Unknown entity: assets.EndUser
 at play.http.DefaultHttpRequestHandler$1.call(DefaultHttpRequestHandler.java:20) ~[com.typesafe.play.play_2.11-2.4.2
 at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153) [org.scala-lang.scala-library-2.11.6.jar
 at controllers.Application.index(Application.java:28) ~[test-investpal.test-investpal-1.0-SNAPSHOT-sans-externalized
 at play.db.jpa.TransactionalAction.call(TransactionalAction.java:16) ~[com.typesafe.play.play-java-jpa_2.11-2.4.2.ja
 at scala.concurrent.Promise$class.complete(Promise.scala:55) [org.scala-lang.scala-library-2.11.6.jar:na]
 at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1184) ~[org.hibernate.hibe
 at play.db.jpa.DefaultJPAApi.withTransaction(DefaultJPAApi.java:136) ~[com.typesafe.play.play-java-jpa_2.11-2.4.2.ja
 at scala.concurrent.impl.Future$.apply(Future.scala:31) ~[org.scala-lang.scala-library-2.11.6.jar:na]
 at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) [com.typesafe.akka
 at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:136) ~[com.typesafe.play.play_2.1
 at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) [org.scala-lang.scala-libra
 at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[com.typesafe.play.play_2.11-2.4.2.jar:2.4.2]
 at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:23) [org.scala-lang.scala-library-2.11.6.
 at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(Routes.scala:95) ~[test-investpal.t
 at play.core.j.JavaAction$$anonfun$7.apply(JavaAction.scala:94) ~[com.typesafe.play.play_2.11-2.4.2.jar:2.4.2]
 at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105) ~[com.typesafe.pla
 at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [org.scala-lang.scala-library-2.11.6.jar:na]
 at play.db.jpa.TransactionalAction.lambda$call$5(TransactionalAction.java:19) ~[com.typesafe.play.play-java-jpa_2.11
 at play.core.j.HttpExecutionContext.execute(HttpExecutionContext.scala:32) ~[com.typesafe.play.play_2.11-2.4.2.jar:2
 at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:103) ~[com.typesafe.play.play_2.11-2.4.2.jar:2.4.2]
 at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(Routes.scala:95) ~[test-investpal.t
 at play.core.j.JavaAction$$anonfun$7.apply(JavaAction.scala:94) ~[com.typesafe.play.play_2.11-2.4.2.jar:2.4.2]
 at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105) ~[com.typesafe.pla
 at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:560) ~[com.typesafe.play.play-iteratees_
 at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) [org.scala-lang.scala-library-2.11.6.
 at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:104) ~[com.typesafe.play.play_2.11-2.4.2
 at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) [org.scala-lang.scala-libra
 at scala.concurrent.Future$.apply(Future.scala:492) ~[org.scala-lang.scala-library-2.11.6.jar:na]
 at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:524) ~[com.typesafe.play.play-iteratees_2.11
 at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:70) [com.typesafe.play.play-iteratees_2.11-2
 at scala.Option.map(Option.scala:146) ~[org.scala-lang.scala-library-2.11.6.jar:na]
 at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) [org.scala-lang.scala-library-2.11.6.
 at play.core.j.JavaAction.apply(JavaAction.scala:94) ~[com.typesafe.play.play_2.11-2.4.2.jar:2.4.2]
 at play.api.libs.iteratee.Iteratee$$anonfun$mapM$1.apply(Iteratee.scala:524) ~[com.typesafe.play.play-iteratees_2.11
 at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:96) ~[com.typesafe.play.play_2.11-2.4.2.jar:2.4.2]
 at play.api.libs.iteratee.Iteratee$$anonfun$flatMap$1$$anonfun$apply$13.apply(Iteratee.scala:536) ~[com.typesafe.pla
 at play.api.libs.iteratee.Iteratee$$anonfun$flatMapM$1.apply(Iteratee.scala:560) ~[com.typesafe.play.play-iteratees_
 ... 6 common frames omitted

这是我的build.sbt:

 name := """test-app"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs
)

libraryDependencies += "postgresql" % "postgresql" % "9.1-901-1.jdbc4"

libraryDependencies ++= Seq(
  javaJpa,
  "org.hibernate" % "hibernate-entitymanager" % "4.3.9.Final"
)

// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator

fork in run := true

这是我的conf/application.conf

db.default.driver=org.postgresql.Driver
db.default.url=${DATABASE_URL}
db.default.logStatements=true
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
db.default.hikaricp.connectionTestQuery="SELECT TRUE"

这是我的应用程序控制器:

package controllers;

import assets.EndUser;
import play.db.jpa.JPA;
import play.db.jpa.Transactional;
import play.mvc.Controller;
import play.mvc.Result;
import views.html.main;

public class Application extends Controller {

    @Transactional
    public Result index() {

        EndUser endUser = new EndUser();

        endUser.setEmail("test@gmail.com");

        JPA.em().persist(endUser);

        return ok(main.render("Test App", "Your new application is ready."));
    }

}

这是我的资产/实体:

package assets;

import javax.persistence.*;

@Entity
@Table(name = "EndUser")
public class EndUser {
    public static final String ENTITY_NAME = "EndUser";
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue
    long id;
    @Column(unique = true)
    private String email;


    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}

这是我的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>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/>
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.hbm2ddl.auto" value="create-drop" />
    </properties>
</persistence-unit>

</persistence>

有人知道如何强制Hibernate/持久性单元在Heroku上生成模式表吗?我也尝试手动创建表,但Hibernate抛出相同的异常,无法找到实体EndUser

共有2个答案

潘宪
2023-03-14

我不需要在persistence.xml中显式定义模型就可以解决这个问题。在我的例子中,我有多个persistence.xml,一个在根项目中,一个在子模块中。一旦我从根项目中删除它,我就能够成功地运行它。看这里

窦涵忍
2023-03-14

我找到了问题所在。它记录在播放迁移https://www.playframework.com/documentation/2.4.x/Migration24#Distribution

只需将PlayKeys.externalizeResources:=false添加到build.sbt。

这里也讨论了这个问题https://github.com/playframework/playframework/issues/4590

 类似资料:
  • 我在Kafka的制作人那个里工作,推动主题中的信息。我用的是融合的Kafka。 github上的喜欢问题 下面是我的模式。avsc文件。 Keys.avsc 测试.avsc 生产者.py 当我尝试注册时,它工作正常,没有错误。但是当我尝试注册之后注册。我得到以下错误。 confluent_kafka.avro.error。ClientError:架构分析失败:未知的命名架构“io.codebrew

  • 虽然使用GraphiQL效果很好,但我的老板要求我实现一个用户界面,用户可以通过诸如checkbox、map relationships之类的UI元素检查呈现给他们的元素,并获取数据,这样做将为用户生成GraphiQL输入,调用API并将结果返回给用户。 所以,基本上这涉及到两代人。从GraphQL模式生成用户界面,并从用户的选择生成GraphQL输入查询。 我搜索了一下,但没有找到任何工具已经做

  • 当我尝试从一个片段导航到另一个片段时,我对新的Android导航架构组件有一个问题,我得到了一个奇怪的错误: 除此之外,其他导航都可以正常工作。 我使用片段的函数findNavController()访问导航控制器。 任何帮助将不胜感激。

  • 我是JMeter的新手。我相信我已经成功安装了它,并且正在运行脚本记录器设置(http://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf)。当我启动用于拦截浏览器请求的JMeter代理服务器时,应该在jeter/bin文件夹中生成一个名为ApacheJMeterTemporaryRootCA.crt的文件。它不是。所以,我无法

  • 问题内容: 我正在尝试入门Hibernate 2nd Edition,而我一直试图将简单的工作示例与HSQLDB结合在一起。 当我跑步时,我得到 这是我得到的: Message.java PopulateMessages.java build.properties hibernate.cfg.xml build.xml 问题答案: 您的实体注释不正确, 必须 使用注释。您可以使用Hibernate

  • 问题内容: 我真的很想了解我的代码发生了什么。 我有一个独立的应用程序,它使用spring和Hibernate作为JPA,我正在尝试使用单个主类运行测试 我的主班 我的应用程序上下文是: 我的用户模型是: 我的DAO是: 这是我运行程序时出现的我的stacktrace错误: 问题答案: 您必须在会话工厂配置中列出您的类。如果使用,则可以自动发现实体。 为了在hibernate和spring中使用注