derjust/spring-data-dynamodb

Table with Kotlin Primitives hash and range key

Opened this issue · 1 comments

Expected Behavior

Following the exact example as in https://github.com/derjust/spring-data-dynamodb/wiki/Composite-Primary-Keys-Kotlin-Example runs successfully.

When I change the foobarCode datatype to Long instead of String, I expect the test to pass same way.

Actual Behavior

If I change the foobarCode from String to Long as in

@field:DynamoDBHashKey
   var foobarCode: String? = null,

and corresponding data type changes in FoobarEntry, FoobarRepository and FoobarRepositoryTest, I get the same error as mentioned in - #240

Debugging the code I see that
ReflectionUtils.findMethod(domainType, setterMethodName, method.getReturnType()) in the method: org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl#DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl returns null and the debug window shows the method in the class is long and not Long.

Caused by: java.lang.IllegalArgumentException: Unable to find hash key field or setter method on class

Steps to Reproduce the Problem

  1. Replace type of foobarCode from String to Long in FoobarEntryId, FoobarEntry, FoobarRepository and FoobarRepositoryTest
  2. Run the Spring boot application or the test

Specifications

  • Spring Data DynamoDB Version: 5.1.0 (2.1)
  • Spring Data Version: 2.1.6.RELEASE
  • AWS SDK Version: 1.11.550
  • Java Version: 1.8.0_192
  • Platform Details: Mac OS X 10.14.4
  • Kotlin JVM - 1.2.71

Found that Kotlin classes "Long", "Int" etc are actually primitive wrappers represented as classes and access through reflection does return long, int Java primitives.

So, I did try java.lang.Long instead of Long in my kotlin file. It shows a warning that you shouldn't be using java.lang.Long in kotlin files, but the app works fine.

Since the only place we are worrying about the type used in reflections is

org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl#DynamoDBHashAndRangeKeyExtractingEntityMetadataImpl
hashKeySetterMethod = ReflectionUtils.findMethod(domainType, setterMethodName,
							method.getReturnType());

can we have some intelligent type coverters for known primitives like Long, Int etc?