Skip to content

Spring JPA - type LocalDateTime in Projection type must be an interface! #24528

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

Closed
Aiksandr opened this issue Dec 16, 2020 · 4 comments
Closed
Labels
for: external-project For an external project and not something we can fix

Comments

@Aiksandr
Copy link

Aiksandr commented Dec 16, 2020

In Spring boot 2.4.1 & 2.4.0
When use projection with field LocalDateTime

public interface Report {
    UUID getId();
    LocalDateTime getCreateDate();
}

after fetch it from DB, get exception when try access to LocalDateTime field getCreateDate()

Caused by: java.lang.IllegalArgumentException: Projection type must be an interface!
	at org.springframework.util.Assert.isTrue(Assert.java:121)
	at org.springframework.data.projection.ProxyProjectionFactory.createProjection(ProxyProjectionFactory.java:105)
	at org.springframework.data.projection.SpelAwareProxyProjectionFactory.createProjection(SpelAwareProxyProjectionFactory.java:45)
	at org.springframework.data.projection.ProjectingMethodInterceptor.getProjection(ProjectingMethodInterceptor.java:160)
	at org.springframework.data.projection.ProjectingMethodInterceptor.potentiallyConvertResult(ProjectingMethodInterceptor.java:108)
	at org.springframework.data.projection.ProjectingMethodInterceptor.invoke(ProjectingMethodInterceptor.java:85)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)

And in previews versions it works ok

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 16, 2020
@wilkinsona
Copy link
Member

Spring Data has required projection types to be an interface since projection support was introduced so it's not clear why it's started to fail upon upgrade to Spring Boot 2.4 and, therefore, Spring Data 2020.0. I suspect it'll be due to a change somewhere in Spring Data but I can't tell for certain from what you've shared thus far. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Dec 16, 2020
@Aiksandr
Copy link
Author

Hello @wilkinsona , i made sample project, if You run it like usual Spring app, that will throw this exception
https://github.com/Aiksandr/spring-jpa-demo

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 16, 2020
@wilkinsona
Copy link
Member

Thanks for the sample. I've reproduced the problem.

With Spring Data Neumann (used by Spring Boot 2.3), the projection isn't used and the java.sql.Timestamp from the DB is converted to a LocalDateTime by the conversion service's object to object converter. With Spring Data 2020.0 (used by Spring Boot 2.4), the object to object converter is removed from the conversion service. This leaves it unable to perform the Timestamp to LocalDateTime conversion so an attempt to use the projection is made instead.

I'm not sure if what you're experiencing is intentional or an unintended side-effect. Please open a Spring Data Commons issue so that the Data team can take a look and also comment here with a link to the issue so that we can follow along.

@wilkinsona wilkinsona added for: external-project For an external project and not something we can fix and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Dec 16, 2020
@Aiksandr
Copy link
Author

Ok, Created issue in Data Commons https://jira.spring.io/browse/DATACMNS-1847

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

3 participants