Scala Neo4j OGM - 不会扫描带注释的NodeEntity类 - IllegalArgumentException

时间:2018-03-08 19:03:49

标签: scala neo4j neo4j-ogm

问题:带注释的类未加载到类映射中。

我对如何使用OGM的理解:

  • 将您的域名(包括NodeEntity注释类)传递给SessionFactory
  • 打开Session。此时,在幕后,构建了带注释的NodeEntity类的类映射。这在第3行的堆栈跟踪中被引用为“构建注释类映射”。你会在下一行看到它映射0
  • 将带注释的NodeEntity类的实例传递给session.save
  • 您的实体现已保存在Neo4j中!

this sample project中,域名为testdomain,唯一带注释的NodeEntityPerson在同一文件中定义。我希望这可以消除任何问题,找到在幕后构建到持久化类映射中的类。但是如日志所示,类映射不考虑我传递给SessionFactory的域。

这可以防止将任何数据保存到Neo。

您可以克隆项目并自行运行应用程序以重现问题(README中的说明)。

堆栈跟踪:

[info] Running testdomain.Test
2018-03-08 13:54:09 INFO  DomainInfo:160 - Starting Post-processing phase
2018-03-08 13:54:09 INFO  DomainInfo:126 - Building annotation class map
2018-03-08 13:54:09 INFO  DomainInfo:139 - Building interface class map for 0 classes
2018-03-08 13:54:09 INFO  DomainInfo:215 - Post-processing complete
[error] (run-main-0) java.lang.IllegalArgumentException: Class class testdomain.Person is not a valid entity class. Please check the entity mapping.
[error] java.lang.IllegalArgumentException: Class class testdomain.Person is not a valid entity class. Please check the entity mapping.
[error]         at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:88)
[error]         at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:40)
[error]         at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:469)
[error]         at testdomain.Test$.delayedEndpoint$testdomain$Test$1(Test.scala:32)
[error]         at testdomain.Test$delayedInit$body.apply(Test.scala:26)
[error]         at scala.Function0.apply$mcV$sp(Function0.scala:34)
[error]         at scala.Function0.apply$mcV$sp$(Function0.scala:34)
[error]         at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
[error]         at scala.App.$anonfun$main$1$adapted(App.scala:76)
[error]         at scala.collection.immutable.List.foreach(List.scala:389)
[error]         at scala.App.main(App.scala:76)
[error]         at scala.App.main$(App.scala:74)
[error]         at testdomain.Test$.main(Test.scala:26)
[error]         at testdomain.Test.main(Test.scala)
[error]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error]         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[error]         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[error]         at java.lang.reflect.Method.invoke(Unknown Source)
[error]         at sbt.Run.invokeMain(Run.scala:93)
[error]         at sbt.Run.run0(Run.scala:87)
[error]         at sbt.Run.execute$1(Run.scala:65)
[error]         at sbt.Run.$anonfun$run$4(Run.scala:77)
[error]         at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error]         at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:10)
[error]         at sbt.TrapExit$App.run(TrapExit.scala:252)
[error]         at java.lang.Thread.run(Unknown Source)
[error] java.lang.RuntimeException: Nonzero exit code: 1
[error]         at sbt.Run$.executeTrapExit(Run.scala:124)
[error]         at sbt.Run.run(Run.scala:77)
[error]         at sbt.Defaults$.$anonfun$bgRunTask$5(Defaults.scala:1169)
[error]         at sbt.Defaults$.$anonfun$bgRunTask$5$adapted(Defaults.scala:1164)
[error]         at sbt.internal.BackgroundThreadPool.$anonfun$run$1(DefaultBackgroundJobService.scala:366)
[error]         at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error]         at scala.util.Try$.apply(Try.scala:209)
[error]         at sbt.internal.BackgroundThreadPool$BackgroundRunnable.run(DefaultBackgroundJobService.scala:289)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[error]         at java.lang.Thread.run(Unknown Source)
[error] (Compile / run) Nonzero exit code: 1
[error] Total time: 6 s, completed Mar 8, 2018 1:54:09 PM

我搜索过高和低以尝试解决此问题。但是,我是scala的新手,所以这一定是我想念的简单,对吧?

-skyfer

1 个答案:

答案 0 :(得分:0)

此问题已通过对Neo4j OGM库的修改得到解决。详细信息在this issue的github上。