You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are migrating from OGM to SDN. In OGM @DateLong works well with COALESCE. However, in SDN the same causes an error.
Give following artifacts.
DashboardLite.java
import java.util.Date;
import lombok.Value;
import org.springframework.data.neo4j.core.support.DateLong;
@Value
public class DashboardLite {
String id;
@DateLong
Date created;
@DateLong
Date updated;
@DateLong
Date modified;
}
DashboardRepository.java
Note that entity mapping type is Dashboard and return type is DashboardLite POJO
@Test
fun findLiteById() {
clean()
val id = "dash-1"
val dashboard = DashboardStub.getOne(id = id)
dashboard.created = Date()
dashboard.updated = Date()
dashboardRepository.save(dashboard)
assertingWith(dashboardRepository.findLiteById(id).get()) {
assertThat(it.id).isEqualTo(id)
assertThat(it.modified).isNotNull
}
}
Error
Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [org.neo4j.driver.internal.value.IntegerValue] to type [java.util.Date] for value '1630075360851'; nested exception is org.neo4j.driver.exceptions.value.Uncoercible: Cannot coerce INTEGER to Java String
at app//org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:47)
at app//org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:192)
at app//org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:175)
at app//org.springframework.data.neo4j.core.mapping.DefaultNeo4jConversionService.lambda$readValue$0(DefaultNeo4jConversionService.java:74)
at app//org.springframework.data.neo4j.core.mapping.DefaultNeo4jConversionService.readValueImpl(DefaultNeo4jConversionService.java:96)
... 128 more
Caused by: org.neo4j.driver.exceptions.value.Uncoercible: Cannot coerce INTEGER to Java String
at app//org.neo4j.driver.internal.value.ValueAdapter.asString(ValueAdapter.java:91)
at app//org.springframework.data.neo4j.core.convert.AdditionalTypes.asDate(AdditionalTypes.java:228)
at app//org.springframework.data.convert.DefaultConverterBuilder$ConfigurableGenericConverter.convert(DefaultConverterBuilder.java:151)
at app//org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41)
... 132 more
Workaround
The same test pass by changing modified's data type from Date to long and remove @DateLong annotation.
// @DateLong
long modified;
Question
Should @DateLong convert COALESCE returned long to Date?
The text was updated successfully, but these errors were encountered:
It is always great to have colleagues helping out to see what has been missed.
So what you are trying to do is to apply @DateLong (or in general, converters), to DTO based projections. This is currently not supported, that's the reason for the failure you seeing. I am gonna fix that.
Also, properties in the projection (your DashboardLite) that already exist in the domain and are annotated there, don't need to be annotated again. So the correct projection will be (with the enhancement in place)
michael-simons
changed the title
@DateLong and COALESCE do not work well together
Custom converters (such as DateLongConverter via @DateLong) don't work with projections.
Aug 30, 2021
SDN v6.1.4 via Spring Data v2.5.4
We are migrating from OGM to SDN. In OGM
@DateLong
works well withCOALESCE
. However, in SDN the same causes an error.Give following artifacts.
DashboardLite.java
DashboardRepository.java
Note that entity mapping type is
Dashboard
and return type isDashboardLite
POJOTest
Error
Workaround
The same test pass by changing
modified
's data type fromDate
tolong
and remove@DateLong
annotation.Question
Should
@DateLong
convertCOALESCE
returnedlong
toDate
?The text was updated successfully, but these errors were encountered: