【问题标题】:Neo4J OGM field primary id is null in ScalaNeo4J OGM 字段主 ID 在 Scala 中为空
【发布时间】: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。

【问题讨论】:

    标签: scala neo4j neo4j-ogm


    【解决方案1】:

    分配错误。这有效:

    @Id
    @GeneratedValue
    var id: java.lang.Long 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多