【发布时间】:2019-04-09 14:43:20
【问题描述】:
这是我的节点实体类:
@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。
【问题讨论】: