Skip to content

The attribute 'id' is not mapped to a Graph property in ReactiveNeo4jTemplate #2676

Closed
@yacosta738

Description

@yacosta738

Hello everyone, I'm having a problem with my domain layer. I have an entity that is shared between Postgres and Neo4j. These are my models.

import com.astrum.data.ModifiableULIDEntity
import com.astrum.data.annotation.Key
import org.springframework.data.neo4j.core.schema.Node
import org.springframework.data.relational.core.mapping.Table

@Table("persons")
@Node("persons")
data class Person(
    @Key
    var name: String,
    var age: Int,
) : ModifiableULIDEntity()
import com.astrum.data.annotation.GeneratedValue
import java.time.Instant

abstract class ModifiableULIDEntity : ULIDEntity(), Modifiable {
    @GeneratedValue
    override var createdAt: Instant? = null

    @GeneratedValue
    override var updatedAt: Instant? = null
}
import com.astrum.data.annotation.GeneratedValue
import com.astrum.ulid.ULID
import org.springframework.data.annotation.Id
import org.springframework.data.neo4j.core.schema.Id as IdGraph

abstract class ULIDEntity : Entity<ULID>() {
    @Id
    @IdGraph
    @GeneratedValue
    override var id: ULID = ULID.randomULID()
}
abstract class Entity<ID> {
    abstract var id: ID

    override fun hashCode(): Int {
        return id.hashCode()
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as Entity<*>

        return id == other.id
    }
}

The problem is with the Neo4j part when I try to save a Person type entity. In the following class I use in a test it fails with the following error.

The attribute 'id' is not mapped to a Graph property
org.springframework.data.mapping.MappingException: The attribute 'id' is not mapped to a Graph property
	at app//org.springframework.data.neo4j.core.mapping.DefaultNeo4jPersistentProperty.getPropertyName(DefaultNeo4jPersistentProperty.java:261)
	at app//org.springframework.data.neo4j.core.mapping.DefaultNeo4jPersistentEntity.computeIdDescription(DefaultNeo4jPersistentEntity.java:420)
Create Person migration

Required identifier property not found for class com.astrum.data.entity.Person
java.lang.IllegalStateException: Required identifier property not found for class com.astrum.data.entity.Person
	at org.springframework.data.mapping.PersistentEntity.getRequiredIdProperty(PersistentEntity.java:135)
	at org.springframework.data.neo4j.core.mapping.DefaultNeo4jIsNewStrategy.basedOn(DefaultNeo4jIsNewStrategy.java:57)
	at org.springframework.data.neo4j.core.mapping.DefaultNeo4jPersistentEntity.getFallbackIsNewStrategy(DefaultNeo4jPersistentEntity.java:196)
import com.astrum.data.entity.Person
import com.astrum.data.migration.Migration
import kotlinx.coroutines.reactive.awaitFirstOrNull
import org.springframework.data.neo4j.core.ReactiveNeo4jTemplate

class CreatePerson(
    private val neo4jTemplate: ReactiveNeo4jTemplate
) : Migration {
    override suspend fun up() {
        println("Create Person migration")
        neo4jTemplate.save<Person>(Person("test", 10)).awaitFirstOrNull()
    }

    override suspend fun down() {
        neo4jTemplate.deleteAll(Person::class.java).awaitFirstOrNull()
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: works-as-expectedAn issue that is not valid as the error or outcome is expected.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions