我是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”。
我可能做错了什么?我试图寻找一个解决方案,但到目前为止我看到的所有线程都没有帮助。
答案 0 :(得分:1)
对于那些可能在没有playframework的情况下使用ebean而面临此错误的人
在模型中,如果要在任何函数中返回POJO类,并且在运行单元测试用例或其他场景时发生此错误,则在POJO类或任何不相关的模型类中添加setter和getter方法,并使用这些函数处理它。不要直接访问成员变量并操纵它们。产生这个错误。当我生成所有getter / setter时,它解决了我的问题