Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same field as DynamoDBRangeKey and DynamoIndexDBRangeKey is causing issue #76

Open
jaychapani opened this issue Mar 13, 2017 · 2 comments

Comments

@jaychapani
Copy link

jaychapani commented Mar 13, 2017

Hello Experts,

Below is the code that I am using in my application.
DateTime is the field used as sort key for table and GSI.
When we query as below using below method in the interface which extends DynamoDBCrudRepository<DemoClass, DemoClassPrimaryKey>. I am getting exception as mentioned below.

List<DemoClass> findByDemoSerialNumberAndDateTimeBetween(String demoSerialNumber, String startDateTime, String endDateTime);

Exception
Illegal query expression: No hash key condition is applicable to the specified index (DemoAttribId-DateTime-index).

Also when I am calling below method, It is using scan instead of query.

List<DemoClass> findByDemoAttribIdInAndDateTimeBetween(List<Long> demoAttribIds, String startDateTime, String endDateTime);
public class DemoClass {

    //Seeds for hash builder, must be non-zero, odd numbers, unique per class
    private final int HASH_SEED_A = 19;
    private final int HASH_SEED_B = 43;
 
    public DemoClass() {
        this.demoClassPrimaryKey = new demoClassPrimaryKey();
    }
 
    @Id
    private DemoClassPrimaryKey demoClassPrimaryKey;
 
    @DynamoDBHashKey(attributeName = "DemoSerialNumber")
    public String getDemoSerialNumber() { return demoClassPrimaryKey.getDemoSerialNumber(); }
    public void setDemoSerialNumber(String demoSerialNumber) { demoClassPrimaryKey.setDemoSerialNumber(demoSerialNumber); }
 
    @DynamoDBIndexRangeKey(attributeName = "DateTime", globalSecondaryIndexName="DemoAttribId-DateTime-index")
    @DynamoDBRangeKey(attributeName = "DateTime")
    public String getDateTime() { return demoClassPrimaryKey.getDateTime(); }
    public void setDateTime(String dateTime) { demoClassPrimaryKey.setDateTime(dateTime); }
 
    @DynamoDBIndexHashKey(attributeName = "DemoAttribId", globalSecondaryIndexName="DemoAttribId-DateTime-index")
    @Getter
    @Setter
    private Long demoAttribId;
    
 
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
 
        DemoClass demoClass = (DemoClass) o;
 
        return new EqualsBuilder()
                .append(demoClassPrimaryKey, demoClass.demoClassPrimaryKey)
                .append(getDemoSerialNumber(), demoClass.getDemoSerialNumber())
                .append(getDateTime(), demoClass.getDateTime())
                .append(getDemoAttribId(), demoClass.getDemoAttribId())
                .isEquals();
    }
 
    @Override
    public int hashCode() {
        return new HashCodeBuilder(HASH_SEED_A, HASH_SEED_B)
                .append(getDemoSerialNumber())
                .append(getDateTime())
                .append(getDemoAttribId())
                .toHashCode();
    }
}

@NoArgsConstructor
public class DemoClassPrimaryKey implements Serializable {
    // Seeds for hash builder, must be non-zero, odd numbers, unique per class
    private final int HashSeedA = 7;
    private final int HashSeedB = 23;
 
    @Getter
    @Setter
    @DynamoDBHashKey
    private String demoSerialNumber;
 
    @Getter
    @Setter
    @DynamoDBRangeKey
    private String dateTime;
 
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
 
        DemoClassPrimaryKey demoClassPrimaryKey = (DemoClassPrimaryKey) o;
 
        return new EqualsBuilder()
                .append(getDemoSerialNumber(), demoClassPrimaryKey.getDemoSerialNumber())
                .append(getDateTime(), demoClassPrimaryKey.getDateTime())
                .isEquals();
    }
 
    @Override
    public int hashCode() {
        return new HashCodeBuilder(HashSeedA, HashSeedB)
                .append(demoSerialNumber)
                .append(dateTime)
                .toHashCode();
    }
}
@derjust
Copy link
Owner

derjust commented Feb 3, 2018

First test with #131 can't reproduce this per-say

@raj111
Copy link

raj111 commented Feb 9, 2023

Hi, Is there an ETA on this issue. thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants