question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[v5.0.1 Regression] Query Creation Uses Attribute Name instead of Column Name

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pluttrellcommented, Feb 2, 2018

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.

1reaction
pluttrellcommented, Jan 28, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring-Data-Jpa Repository - Underscore on Entity Column ...
I solved this error by renaming field to the name without underscore. @Column(name = "municipal_id", nullable = false) private Integer municipalId; ...
Read more >
Extracting, transforming and selecting features - Apache Spark
Numeric columns: For numeric features, the hash value of the column name is used to map the feature value to its index in...
Read more >
IBM Cognos Dynamic Query
The Cognos BI server interprets user gestures and report specifications and translates them into data-retrieval queries that are tailored to the most popular ......
Read more >
JSON_TABLE
JSON_query_column This clause evaluates JSON data in the same manner as the JSON_QUERY function, that is, it finds one or more specified JSON...
Read more >
15.2 Linear regression with lm() - YaRrr! The Pirate's Guide to R
Warning! The dataframe that you use in the newdata argument to predict() must have column names equal to the names of the coefficients...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found