michaellavelle / spring-data-dynamodb

Simplifies the development of creating an Amazon DynamoDB-based Java data access layer
https://derjust.github.io/spring-data-dynamodb/
Apache License 2.0
169 stars 284 forks source link

BUG: CountByHashAndRangeKeyQuery and CountByHashKeyQuery #55

Closed wanmifam closed 9 years ago

wanmifam commented 9 years ago

DynamoDBMapper don't support: dynamoDBMapper.load(Long.class, hashKey,rangeKey) or dynamoDBMapper.load(Long.class, hashKey) If we call CountByHashKeyQuery.getSingleResult() or CountByHashAndRangeKeyQuery.getSingleResult(), we will meet error.

michaellavelle commented 9 years ago

I'm afraid I don't have enough information to look into this - I can't tell from this stack trace what your use case is.

Looks like a problem instantiate your hash key class - could you provide details of your hash key class?

What is the use case here? - when does this error occur?

Also, I see a class in the stack trace I don't recognise - what is the MultiServiceDynamoDBTemplate class?

Thanks,

Michael

wanmifam commented 9 years ago

@michaellavelle I'm sorry that I didn't provide enough information about this bug. Thank you very much because of creating great project! It help me very much in real product!

I create a project to describe this bug. Link: https://drive.google.com/file/d/0B_CjEBcszSIBd2RmczJOeXZKeTA/view?usp=sharing

To see this bug, just modify some fields relate with DynamoD AWS in class: org.spring.data.dynamodb.bug.main.Main

Thanks, Minh Quan

michaellavelle commented 9 years ago

Hi - could you please share the project on GitHub instead of a link to a zip file.?

Thanks,

Michael

wanmifam commented 9 years ago

I'm sorry to bother you!

This is project on GitHub: https://github.com/wanmifam/springdata-dynamoDB-bug

Thank you for your kind patience and understanding! :)

michaellavelle commented 9 years ago

Thank you for raising this - there was a bug with this use case - really appreciate you bringing it to my attention.

I've fixed the issue in the latest snapshot build (1.0.2-SNAPSHOT) - this build requires a later version of aws-sdk (1.9.25) than you are using.

The issue happened when counting resultsets for PagedQueries when the primary key is specified, such as threadRepository.findByForumNameAndSubject.

I see in your example that you are calling this method, and you have this annotated with @EnableScan.

Just wanted to say that if you are specifying both ForumName and Subject ( both parts of the primary key), you would be able to change this to

threadRepository.findOne(threadId);

where threadId has the forumName and subject set.

This way you would not need to @EnableScan for this query, as you are searching by primary key.

Hope this helps - thanks again.

Michael

wanmifam commented 9 years ago

Thank you for your help!

It help me a lot of! :+1:

Some time we use reflection to mapping attribute name with method name, so the method findOne(primaryKey) don't use in this case. Whatever I love your project, It help me a lot of (about DynamoDB and Spring Data technology)! We applied Spring Data DynamoDB in our real product, and our customer's very satisfy!

Again Thank you so much for your beautiful project!

Best regards, Minh Quan.

michaellavelle commented 9 years ago

You're welcome - thanks for your interest in the project - glad it's helped you.

Cheers,

Michael