-
Notifications
You must be signed in to change notification settings - Fork 617
Support default, primitive Kotlin attributes. #2276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Do you have a reproducer at hand? Cannot reproduce it on 6.0.x nor 6.1.x? The
Tried
|
Sorry, my mistake. It actually work with the String, but it doesn't seem to work when the default value is for a primitive. Here is my sample @Node("TestPerson")
data class TestPersonEntity(
@Id
val id: String,
@Property("name")
val name: String = "Unknown", // this works
val otherPrimitive: Int = 32, // <<- this doesn't
)
@Node("TestDepartment")
data class TestDepartmentEntity(
@Id
val id: String,
@Property("name")
val name: String
)
data class PersonProjection(
val person: TestPersonEntity,
val department: TestDepartmentEntity
)
interface TestPersonRepositoryProjection : Neo4jRepository<TestPersonEntity, String> {
@Query(
"""
MATCH (person:TestPerson)
MATCH (person)-[:MEMBER_OF]->(department:TestDepartment)
return person, department
"""
)
fun findPeople(): List<PersonProjection>
}
@Configuration
class TestRepository(
private val repository: TestPersonRepositoryProjection,
) {
init {
println(repository.findPeople())
}
} I tested with And I executed the following query in Neo4j
|
That is helpful. Thank you. Should be able to safely reproduce it. It will
probably fail with pure Java, too.
Thanks for reporting!
Sunny Pelletier ***@***.***> schrieb am Mi. 2. Juni 2021 um
17:53:
… Sorry, my mistake. It actually work with the String, but it doesn't seem
to work when the default value is for a primitive. Here is my sample
@node("TestPerson")data class TestPersonEntity(
@id
val id: String,
@Property("name")
val name: String = "Unknown", // this works
val otherPrimitive: Int = 32, // <<- this doesn't
)
@node("TestDepartment")data class TestDepartmentEntity(
@id
val id: String,
@Property("name")
val name: String
)
data class PersonProjection(
val person: TestPersonEntity,
val department: TestDepartmentEntity
)
interface TestPersonRepositoryProjection : Neo4jRepository<TestPersonEntity, String> {
@query(
""" MATCH (person:TestPerson) MATCH (person)-[:MEMBER_OF]->(department:TestDepartment) return person, department """
)
fun findPeople(): List<PersonProjection>
}
@Configurationclass TestRepository(
private val repository: TestPersonRepositoryProjection,
) {
init {
println(repository.findPeople())
}
}
I tested with int and boolean and I get the same error. I assumed it's
for all primitives, but I haven't tested all of them.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#2276 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEAQLY5LPFWJ6HVIBKR3V3TQZHW3ANCNFSM4564CL6A>
.
|
This bugfix allows primitive attributes with defaults in Kotlin based domain classes. It comes at a price however: We cannot throw a mapping exception hinting at the fact a primitive had been tried to be assigned with null in standard java. The ` MappingException`’s cause will than be a `NullpointerException`. The value of supporting Kotlin defaults is in this case higher than the error message, which was "received" with a trick anyway (relying on the conversion service that it throws an exception. This fixes #2276.
This bugfix allows primitive attributes with defaults in Kotlin based domain classes. It comes at a price however: We cannot throw a mapping exception hinting at the fact a primitive had been tried to be assigned with null in standard java. The ` MappingException`’s cause will than be a `NullpointerException`. The value of supporting Kotlin defaults is in this case higher than the error message, which was "received" with a trick anyway (relying on the conversion service that it throws an exception. This fixes #2276.
Default values for fields are not supported for constructor of node entities when querying the database with a custom query.
with the following data class
and the following repository
calling
personRepository.findAll()
results inThe text was updated successfully, but these errors were encountered: