scala - Neo4J OGM 字段主 ID 在 Scala 中为空
问题描述
这是我的节点实体类:
@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
推荐阅读
- windows-10 - Windows 10 屏幕锁定最后机会
- ansible - 将文件下载到 ansible 控制器而不是远程机器
- sql-server - 如果工作表名称中有空格(SSIS),如何跳过 OpenRowset 中 xlsx 源的前几行?
- php - Laravel 邮件队列中断西里尔文发件人姓名编码
- ansible - 如何检查文件中的目录列表,但某些条目有多个目录,以逗号分隔
- dictionary - Julia 将 NamedTuple 转换为 Dict
- java - 对于 PDFBox 加密,是否有任何替代 BouncyCastle 的方法?
- c - 我在打印 char** 数组时遇到问题
- visual-studio-code - Prettier 在“Shift + Alt + F”上缩进 2 个空格而不是 4 个空格
- go - grpc.WithConnectParams.Backoff 和 grpc_retry.WithBackoff 有什么区别?