- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
正如上面的图块,我一直在尝试使用 neo4j-ogm 和 kotlin,但没有成功。如果我尝试保留我的数据,Neo4j 会抛出异常,“类 xxxx 不是有效实体”。
package com.asofttz.micros.administrator.users.testmodels
import org.neo4j.ogm.annotation.GeneratedValue
import org.neo4j.ogm.annotation.Id
import org.neo4j.ogm.annotation.NodeEntity
import org.neo4j.ogm.annotation.Relationship
@NodeEntity
class Actor(var name: String = "") {
@Id
@GeneratedValue
open var id: Long? = null
@Relationship(type = "ACTS_IN", direction = "OUTGOING")
open val movies = hashSetOf<Movie>()
fun actsIn(movie: Movie) {
movies.add(movie)
movie.actors.plus(this)
}
}
@NodeEntity
class Movie(var title: String = "", var released: Int = 2000) {
@Id
@GeneratedValue
open var id: Long? = null
@Relationship(type = "ACTS_IN", direction = "INCOMING")
open var actors = setOf<Actor>()
}
import com.asofttz.micros.administrator.users.testmodels.Actor
import com.asofttz.micros.administrator.users.testmodels.Movie
import org.neo4j.ogm.config.Configuration
import org.neo4j.ogm.session.SessionFactory
import java.util.*
object Neo4j {
val configuration = Configuration.Builder()
.uri("bolt://localhost")
.credentials("neo4j", "password")
.build()
val sessionFactory = SessionFactory(configuration, "test.movies.domain")
fun save() {
val session = sessionFactory.openSession()
val movie = Movie("The Matrix", 1999)
session.save(movie)
val matrix = session.load(Movie::class.java, movie.id)
for (actor in matrix.actors) {
println("Actor: " + actor.name)
}
}
}
apply plugin: 'kotlin'
apply plugin: 'application'
apply plugin: "org.jetbrains.kotlin.plugin.noarg"
repositories {
jcenter()
mavenCentral()
maven { url "http://dl.bintray.com/kotlin/ktor" }
maven { url "https://dl.bintray.com/kotlin/kontlinx" }
}
noArg {
annotation("org.neo4j.ogm.annotation.NodeEntity")
annotation("org.neo4j.ogm.annotation.RelationshipEntity")
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "io.ktor:ktor:$ktor_version"
compile "io.ktor:ktor-server-netty:$ktor_version"
compile project(":asoftlibs:micros:administrator:users:users-jvm")
compile 'org.neo4j:neo4j-ogm-core:3.1.2'
compile 'org.neo4j:neo4j-ogm-bolt-driver:3.1.2'
}
kotlin {
experimental {
coroutines "enable"
}
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
sourceCompatibility = "1.8"
最佳答案
编辑:没有解释的 super 简短回答是:在您的示例中,您为类扫描配置了错误的包。您正在使用 val sessionFactory = SessionFactory(configuration, "test.movies.domain")
打开 session 但它必须是 val sessionFactory = SessionFactory(configuration, "com.asofttz.micros.administrator.users.testmodels")
从你的模型的包声明来看。但此外,请参阅我的较长版本以获取一些最佳实践和解释:
在此处找到完整且有效的示例作为要点:Minimal Kotlin/Gradle Example for Neo4j OGM
让我带你了解一下:
在 build.gradle
,定义 No-arg compiler plugin作为构建脚本依赖项。
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-noarg:1.2.51"
}
}
noArg
块来定义应该为哪些类合成无参数构造函数:
noArg {
annotation("org.neo4j.ogm.annotation.NodeEntity")
annotation("org.neo4j.ogm.annotation.RelationshipEntity")
}
@NodeEntity
注释的类和
@RelationshipEntity
应该有一个合成的无参数构造函数。
The no-arg compiler plugin generates an additional zero-argument constructor for classes with a specific annotation.
The generated constructor is synthetic so it can’t be directly called from Java or Kotlin, but it can be called using reflection.
@NodeEntity
class Actor(var name: String) {
@Id
@GeneratedValue
var id: Long? = null
@Relationship(type = "ACTS_IN", direction = "OUTGOING")
var movies = mutableSetOf<Movie>()
fun actsIn(movie: Movie) {
movies.add(movie)
movie.actors.add(this)
}
}
@NodeEntity
class Movie(var title: String, var released: Int) {
@Id
@GeneratedValue
var id: Long? = null
@Relationship(type = "ACTS_IN", direction = "INCOMING")
var actors = mutableSetOf<Actor>()
}
var
,不是
val
.您可以安全地省略
open
关键字在这里。另请注意,我确实删除了“真实”业务信息的默认参数(此处为标题和发布年份)。
hashSetOf
而是使用
mutableSetOf
.我们可以使用
#add
改变集合本身。
setOf
并利用我们的属性不再是最终的这一事实并改变字段本身:
@NodeEntity
class Actor(var name: String) {
@Id
@GeneratedValue
var id: Long? = null
@Relationship(type = "ACTS_IN", direction = "OUTGOING")
var movies = setOf<Movie>()
fun actsIn(movie: Movie) {
movies += movie
movie.actors += this
}
}
@NodeEntity
class Movie(var title: String, var released: Int) {
@Id
@GeneratedValue
var id: Long? = null
@Relationship(type = "ACTS_IN", direction = "INCOMING")
var actors = setOf<Actor>()
}
movie.actors.plus(this)
的语句。 .这不会改变集合而是创建一个新集合,就像
+
一样。集合的运算符确实如此。
关于Neo4j - OGM 在 Kotlin 中抛出的不是实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52106841/
到目前为止,我一直在我的项目中使用嵌入式 Neo4j 服务器。现在我想使用独立服务器尝试新的 Bolt 协议(protocol),但仅限于我部署的应用程序。为了方便起见,我仍然想在从 IDE 运行(永
使用 session.load() 查询深度 2 时出现超时.我正在使用 Neo4j OGM 1.1.3(尝试从 Spring Data Neo4j 3.4 迁移)。尝试加载 Node 对象 clas
这是我在 PersistenceContext.java 中的代码 package yuzhaoLiu.project.testNeo4j; import org.neo4j.ogm.config.C
我是 Neo4J 的新手,正在尝试通过 java 连接到 Neo4J 服务器。 我的一个独立项目的pom入口如下: org.neo4j neo4j-o
部署 ear 时出现此错误。 org.jboss.msc.service.StartException in service jboss.persistenceunit."test.ear/serve
Neo4j OGM 遇到问题库并与“子类”有关系: @NodeEntity class MyEntity{ @GraphId private Long graphId; ... } c
我正在使用 Neo4j ogm 将许多(超过 20 个)类似的类映射到 neo4j db 中,这些类的不同之处在于关系名称、名称和方向。每个类都仅使用一个相同的方法来实现“Classification
我的 graphDb 中有 3 种类型的节点。 技能、SkillSubCluster 和SkillCluster。一个 Skill 节点连接到一个或多个 SkillSubCluster 节点(一对多关
我开发了两组类 - 第一个只是类,而在第二组中,类派生自接口(interface)。两组类都互相模仿。它们的存储库也相似。但是,存储库对于第一组类(节点和关系)效果很好。对于第二组类,存储库能够插入记
在我的项目中,我有MapNodes,它们通过关系ConnectRelation连接。 ConenctRelation 有一个属性长度。节点及其关系毫无问题地保存到 Neo4J 数据库中。但是当加载节点
我遇到了 neo4j OGM 的问题图书馆,我已按照图书馆 docs page 上的说明进行操作实现一个抽象父实体以包含我的实体的所有共享字段和功能。然后,当我用具体的类继承此类并尝试执行 sessi
我有两个 NodeEntity 类,它们以多对一关系相关(如多对一)。假设许多实体 A 与单个实体 B 相关。我希望能够加载深度大于 0 的实体 B,但不加载许多相关实体 A,并且实际上不需要访问实体
假设我们有一个巨大的 mongodb 集合(大约 60,000,000 条记录),并且我们希望滚动它,当然不想获取大量内存。对于 Hibernate orm 来说,这是可能的,因为有滚动 api 和条
我想使用 py2neo 的 OGM 来表示从一种节点类型到两种节点类型的关系。 我有一个解决方案(如下),仅适用于在数据库中存储节点/关系,并且我找不到在检索关系时正常工作的解决方案。 这是我的例子。
我昨天发现了 Neo4j OGM,并迅速创建了一个新项目来测试它的工作原理。我遇到的一个问题是设置 Relationhip 属性,因为这对我的项目至关重要。这是一个例子: 房间节点: @NodeEnt
在我的 Java 代码中,我有一个查询来匹配树中从根到叶子的最短路径。 Strinq query = "Match path = (p:Root)-[*1..100]-(m:Leaf) " +
我们觉得我们终于对 Neo4j-ogm 中看到的奇怪行为有了解释。我们最初认为这与 equals/hashcode 实现有关,但事实并非如此。 似乎 ogm 保留了图的缓存副本,并且在事务内所有检索都
我正在尝试获取 OGM 上密码查询的结果。基本上,我一直在关注本教程:OGM Tutorial . 我有一个实体接口(interface)(与教程中的接口(interface)相同): pub
正如上面的图块,我一直在尝试使用 neo4j-ogm 和 kotlin,但没有成功。如果我尝试保留我的数据,Neo4j 会抛出异常,“类 xxxx 不是有效实体”。 package com.asoft
有人对 Hibernate OGM 与 Kundera 的使用有反馈吗?我知道这两个框架正在为 NoSQL 解决方案提供 Java 持久性 (JPA) 支持,我想从研究过这两个框架的人的经验中受益。听
我是一名优秀的程序员,十分优秀!