Skip to content

Issue with interface projection for a native informix query #2157

Closed
@sgflt

Description

@sgflt

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions