gpt4 book ai didi

java - 为什么我在增强 ebean scala 实体时收到 java.lang.VerifyError

转载 作者:行者123 更新时间:2023-12-01 11:21:39 25 4
gpt4 key购买 nike

我是 ebean 和 scala/akka 的新手,我正在尝试将最小的案例类保留为 ebean 实体。我的依赖关系如下:

scalaVersion := "2.11.5"

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.3.9",
"com.typesafe.akka" %% "akka-remote" % "2.3.9",
"com.typesafe.akka" %% "akka-cluster" % "2.3.9",
"com.typesafe.akka" %% "akka-testkit" % "2.3.9" % "test",
"org.scalatest" %% "scalatest" % "2.2.4" % "test",
"com.typesafe.slick" %% "slick" % "3.0.0",
"com.typesafe.slick" %% "slick-codegen" % "3.0.0",
"org.sorm-framework" % "sorm" % "0.3.18",
"org.avaje.ebeanorm" % "avaje-ebeanorm" % "4.7.1",
"org.avaje.ebeanorm" % "avaje-ebeanorm-agent" % "4.5.3",
"org.avaje" % "avaje-agentloader" % "1.1.3",
"org.apache.commons" % "commons-pool2" % "2.0")

和我的实体:

package zw.co.esol.eswitch.model

import javax.persistence.Entity
import javax.persistence.Id
import com.avaje.ebean.Model

@Entity
case class Test(@Id id: Long, firstname: String) extends Model

和我的主要:

object ApplicationMain extends App {

val system = ActorSystem("eswitch", ConfigFactory.load())

//system.logConfiguration()

// Load the agent into the running JVM process
if (!AgentLoader.loadAgentFromClasspath("avaje-ebeanorm-agent","debug=1;packages=zw.co.esol.eswitch.model.*")) {
println("avaje-ebeanorm-agent not found in classpath - not dynamically loaded");
}

EbeanDbServer.init
//more code follows.......

和我的 ebean 初始化代码:

object EbeanDbServer {

def init = {

// programmatically build a EbeanServer instance
// specify the configuration...

println("@@ Starting EbeanServer...")

var config = new ServerConfig();
config.setName("pgtest");

// Define DataSource parameters
var postgresDb = new DataSourceConfig();
postgresDb.setDriver("com.mysql.jdbc.Driver");
postgresDb.setUsername("user");
postgresDb.setPassword("password");
postgresDb.setUrl("jdbc:mysql://127.0.0.1:3306/eswitch");
postgresDb.setHeartbeatSql("select count(*) from message");

config.setDataSourceConfig(postgresDb);

// specify a JNDI DataSource
// config.setDataSourceJndiName("someJndiDataSourceName");

// set DDL options...
config.setDdlGenerate(false);
config.setDdlRun(false);

config.setDefaultServer(false);
config.setRegister(false);

var test = Test(1, "stan")
// automatically determine the DatabasePlatform
// using the jdbc driver
// config.setDatabasePlatform(new PostgresPlatform());

// specify the entity classes (and listeners etc)
// ... if these are not specified Ebean will search
// ... the classpath looking for entity classes.

config.addClass(classOf[Test]);

// specify jars to search for entity beans
// config.addJar("someJarThatContainsEntityBeans.jar");

// create the EbeanServer instance
val server: EbeanServer = EbeanServerFactory.create(config);

println("@@ EbeanServer started... : " + server.getName)

}
}

但是我在运行应用程序时得到输出:

ebean-enhance> cls: zw/co/esol/eswitch/model/Test  msg: ... skipping add equals() ... already has equals() hashcode() methods
ebean-enhance> cls: zw/co/esol/eswitch/model/Test msg: enhanced
[error] (run-main-0) java.lang.VerifyError: Bad type on operand stack
[error] Exception Details:
[error] Location:
[error] zw/co/esol/eswitch/model/Test.<init>(JLjava/lang/String;)V @2: invokevirtual
[error] Reason:
[error] Type uninitializedThis (current frame, stack[0]) is not assignable to 'zw/co/esol/eswitch/model/Test'
[error] Current Frame:
[error] bci: @2
[error] flags: { flagThisUninit }
[error] locals: { uninitializedThis, long, long_2nd, 'java/lang/String' }
[error] stack: { uninitializedThis, long, long_2nd }
[error] Bytecode:
[error] 0000000: 2a1f b600 932a 2db6 0096 2ab7 0099 2abb
[error] 0000010: 009b 592a b700 9eb5 00a0 2ab8 00a6 b1
java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
zw/co/esol/eswitch/model/Test.<init>(JLjava/lang/String;)V @2: invokevirtual
Reason:
Type uninitializedThis (current frame, stack[0]) is not assignable to 'zw/co/esol/eswitch/model/Test'
Current Frame:
bci: @2
flags: { flagThisUninit }
locals: { uninitializedThis, long, long_2nd, 'java/lang/String' }
stack: { uninitializedThis, long, long_2nd }
Bytecode:
0000000: 2a1f b600 932a 2db6 0096 2ab7 0099 2abb
0000010: 009b 592a b700 9eb5 00a0 2ab8 00a6 b1

at zw.co.esol.eswitch.database.EbeanDbServer$.init(EbeanDbServer.scala:45)
at zw.co.esol.eswitch.global.ApplicationMain$.delayedEndpoint$zw$co$esol$eswitch$global$ApplicationMain$1(ApplicationMain.scala:28)
at zw.co.esol.eswitch.global.ApplicationMain$delayedInit$body.apply(ApplicationMain.scala:17)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.App$class.main(App.scala:76)
at zw.co.esol.eswitch.global.ApplicationMain$.main(ApplicationMain.scala:17)
at zw.co.esol.eswitch.global.ApplicationMain.main(ApplicationMain.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)

我在 Linux x86_64 上使用 java 版本“1.7.0_55”。

我可能做错了什么?我试图寻找解决方案,但到目前为止我看到的所有线程都没有帮助。

最佳答案

对于一些在没有 playframework 的情况下使用 ebean 可能会遇到此错误的人

在您的模型中,如果您在任何函数中返回 POJO 类,并且在运行单元测试用例或其他场景时发生此错误,则在 POJO 类或任何不相关的模型类中添加 setter 和 getter 方法,并使用这些函数来处理它。不要直接访问成员变量并操作它们。产生此错误。当我生成所有 getter/setter 时,它为我解决了问题

关于java - 为什么我在增强 ebean scala 实体时收到 java.lang.VerifyError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31158281/

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