[v5.0.1 Regression] Query Creation Uses Attribute Name instead of Column Name
See original GitHub issueI’m migrating a Spring Boot 1.5.9 project to Spring Boot 2.0 and thus have upgraded to com.github.derjust:spring-data-dynamodb:5.0.1
. This project contains several tables that use contrived keys and we map them like this:
@Id
private CustomerDocumentId customerDocumentId;
@DynamoDBHashKey(attributeName = "customerId|documentType")
public String getCustomerDocumentKey() {
if (customerDocumentId == null) {
return null;
}
return customerDocumentId.getCustomerDocumentKey();
}
public void setCustomerDocumentKey(String customerDocumentId) {
if (customerDocumentId == null) {
this.customerDocumentId = new CustomerDocumentId();
}
customerDocumentId.setCustomerDocumentKey(customerDocumentId);
}
In case you’re wondering why we have contrived keys like this, it has to do with DynamoDB’s limit to two keys per table… And we have a separate column for the Range key. I just omitted it for brevity.
In our CrudRepository
we have a query method such as this (among others):
@EnableScan
public interface CustomerDocumentRepository extends CrudRepository<CustomerDocument, CustomerDocumentId> {
List<CustomerDocument> findByCustomerDocumentKey(String customerDocumentKey);
}
Notice how we’ve defined the entity property customerDocumentKey
to map the column name customerId|documentType
.
The store operation works perfectly, but when we lookup records using findByCustomerDocumentKey
we get this error:
com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException: CustomerDocument[customerDocumentKey]; no mapping for attribute by name
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperTableModel.field(DynamoDBMapperTableModel.java:94) ~[aws-java-sdk-dynamodb-1.11.268.jar:na]
at org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCriteria.getPropertyAttributeValue(AbstractDynamoDBQueryCriteria.java:501) ~[spring-data-dynamodb-5.0.1.jar:na]
at org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCriteria.withHashKeyEquals(AbstractDynamoDBQueryCriteria.java:395) ~[spring-data-dynamodb-5.0.1.jar:na]
at org.socialsignin.spring.data.dynamodb.repository.query.DynamoDBEntityWithHashAndRangeKeyCriteria.withPropertyEquals(DynamoDBEntityWithHashAndRangeKeyCriteria.java:369) ~[spring-data-dynamodb-5.0.1.jar:na]
at org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCreator.addCriteria(AbstractDynamoDBQueryCreator.java:129) ~[spring-data-dynamodb-5.0.1.jar:na]
at org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCreator.create(AbstractDynamoDBQueryCreator.java:66) ~[spring-data-dynamodb-5.0.1.jar:na]
at org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCreator.create(AbstractDynamoDBQueryCreator.java:40) ~[spring-data-dynamodb-5.0.1.jar:na]
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:115) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:94) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:80) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.socialsignin.spring.data.dynamodb.repository.query.PartTreeDynamoDBQuery.doCreateQuery(PartTreeDynamoDBQuery.java:63) ~[spring-data-dynamodb-5.0.1.jar:na]
at org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQuery.doCreateQueryWithPermissions(AbstractDynamoDBQuery.java:76) ~[spring-data-dynamodb-5.0.1.jar:na]
at org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQuery$CollectionExecution.execute(AbstractDynamoDBQuery.java:98) ~[spring-data-dynamodb-5.0.1.jar:na]
at org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQuery.execute(AbstractDynamoDBQuery.java:294) ~[spring-data-dynamodb-5.0.1.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:597) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:580) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.0.2.RELEASE.jar:5.0.2.RELEASE]
at com.sun.proxy.$Proxy110.findByCustomerDocumentKey(Unknown Source) ~[na:na]
at com.mycompany.CustomerDocumentRepository.findByCustomerDocumentKey(CustomerDocumentRepository.java:52) ~[classes/:na]
In looking at this in the debugger, this line of code org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCriteria.getPropertyAttributeValue(..)
on line 501 is calling the AWS SDK’s DynamoDBMapperTableModel::field
but sending in the attribute name, which in this case is customerDocumentKey
and the AWS SDK only knows about the actual column names, which in this case is customerId|documentType
. I’ve confirmed that the actual column name exists in the fields Map within DynamoDBMapperTableModel
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
Sure thing. I really wasn’t trying to push, just to see if there was a timeframe so we can plan accordingly. And in looking at the bugs, it doesn’t look like it’ll be too long, so I think we can wait.
@derjust And here’s the dependency tree for both branches: https://gist.github.com/pluttrell/0117793ed15c698b58077f90b3d97517. Not sure what specific versions your looking for, but hope this helps.