Skip to content

Issue with interface projection for a native informix query #2157

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
sgflt opened this issue Feb 19, 2021 · 2 comments
Closed

Issue with interface projection for a native informix query #2157

sgflt opened this issue Feb 19, 2021 · 2 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@sgflt
Copy link

sgflt commented Feb 19, 2021

Assume following interface:

interface ProjectionObject {
    CustomTypeObject getCustomType();
}

and use case:

var projection = this.repository.findMyProjectionObject();
projection.getCustomType() // 2.2.10 OK, 2.4.2+ does not work

Converter:

@Converter
public class CustomTypeObjectConverter implements  javax.persistence.AttributeConverter<CustomTypeObject, String> {

  @Override
  public String convertToDatabaseColumn(final CustomTypeObject attribute) {
    return attribute == null ? null : attribute.get();
  }


  @Override
  public CustomTypeObject convertToEntityAttribute(final String dbData) {
    return new  CustomTypeObject(dbData);
  }
}

Repository:

interface CustomObjectRepository extends JpaRepository<CustomObjectEntity, Long> {
  @Query(value = "SELECT FIRST 1 'data' as customType FROM systables", nativeQuery = true)
  CustomObjectType findMyProjectionObject();
}

Entity

@Entity
@Table(name = "systables")
class CustomObjectEntity {
  @Column(name = "tabname")
  @Convert(converter = CustomTypeObjectConverter.class)
  private CustomTypeObject code;
  
  public CustomTypeObject getCustomType() {
    return this.code;
  }
}

With defined javax.persistence.AttributeConverter<CustomTypeObject, String> in Spring 2.2.10 return value was converted without problem.

In spring Boot 2.4.2 and 2.4.3 conversion throws:

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:108)
	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)
	at org.springframework.data.projection.ProxyProjectionFactory$TargetAwareMethodInterceptor.invoke(ProxyProjectionFactory.java:253)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)

Issue is related to #1798 and spring-projects/spring-data-commons#2260.

Caused probably by spring-projects/spring-data-commons#459 when Object to Object mapping has been removed.

CONVERSION_SERVICE.removeConvertible(Object.class, Object.class);
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 19, 2021
@sgflt
Copy link
Author

sgflt commented Feb 23, 2021

Also may be related to #2058

@schauder schauder added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 1, 2021
@schauder
Copy link
Contributor

schauder commented Mar 1, 2021

We don't intend to support arbitrary conversions for projections.

It was working just by accident in previous versions. Sorry for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants