Neo4J OGM 字段主 ID 在 Scala 中为空
Neo4J OGM field primary id is null in Scala
这是我的节点实体class:
@NodeEntity
class SutStateEntity(
@Id
@GeneratedValue
@Index(unique = true)
val id: String) {
def this(sutStateIdentifier: SutStateIdentifier) = this(sutStateIdentifier.hash)
def this() = this("")
}
我正在使用 sutStateIdentifier 的唯一哈希值作为我的 ID。
当我将 SutStateEntity 存储在事务中时:
val sutStateEntity = new SutStateEntity(sutStateIdentifier)
session.save(sutStateEntity)
我得到以下异常:
Exception in thread "main" org.neo4j.ogm.exception.core.MappingException: `Field with primary id is null for entity ....SutStateEntity@34aa8b61`
我了解到,如果我没有指定我指定的默认构造函数,就会发生此错误。
编辑:
以下示例有效:
@Id
@GeneratedValue
var id: java.lang.Long = 0L
我想,我必须将字段 id 更改为 var,但如果我使用字符串,它仍然不起作用。甚至没有 java.lang.String.
赋值错误。这有效:
@Id
@GeneratedValue
var id: java.lang.Long
这是我的节点实体class:
@NodeEntity
class SutStateEntity(
@Id
@GeneratedValue
@Index(unique = true)
val id: String) {
def this(sutStateIdentifier: SutStateIdentifier) = this(sutStateIdentifier.hash)
def this() = this("")
}
我正在使用 sutStateIdentifier 的唯一哈希值作为我的 ID。 当我将 SutStateEntity 存储在事务中时:
val sutStateEntity = new SutStateEntity(sutStateIdentifier)
session.save(sutStateEntity)
我得到以下异常:
Exception in thread "main" org.neo4j.ogm.exception.core.MappingException: `Field with primary id is null for entity ....SutStateEntity@34aa8b61`
我了解到,如果我没有指定我指定的默认构造函数,就会发生此错误。
编辑: 以下示例有效:
@Id
@GeneratedValue
var id: java.lang.Long = 0L
我想,我必须将字段 id 更改为 var,但如果我使用字符串,它仍然不起作用。甚至没有 java.lang.String.
赋值错误。这有效:
@Id
@GeneratedValue
var id: java.lang.Long