Hi ,
As one of my application requirement which involves dynamodb I have to segregate my key columns and other non-key columns in separate java classes and then form the underlying dynamodb table using these classes.
I achieved this by writing a separate class containing only the key attribute and annotated the class with DynamoDBDocument and then in my table definition class I added this class as a field annotated with DynamoDBIgnore , then I wrote the getter setter for this field's inner variables (which are actually the keys). I marked the getter as the DynamoHash and DynamoRangeKeys accordingly . Life so far was easier
Now the problem is I have a table containing single partition key (this table only has hashkeys without any range keys) and the above approach is not working here
Please help me with identifying what needs to be done as literally now I am running out of options.
Actual Behavior
My Crud Repository is failing while performing operation with this error
Expected ID type to be the same as the return type of the hash key method ( class java.lang.String ) : class com.yantriks.yso.organization.services.core.dao.key.DynamoOrgKey",
Expected Behavior
Hi , As one of my application requirement which involves dynamodb I have to segregate my key columns and other non-key columns in separate java classes and then form the underlying dynamodb table using these classes. I achieved this by writing a separate class containing only the key attribute and annotated the class with DynamoDBDocument and then in my table definition class I added this class as a field annotated with DynamoDBIgnore , then I wrote the getter setter for this field's inner variables (which are actually the keys). I marked the getter as the DynamoHash and DynamoRangeKeys accordingly . Life so far was easier Now the problem is I have a table containing single partition key (this table only has hashkeys without any range keys) and the above approach is not working here Please help me with identifying what needs to be done as literally now I am running out of options.
Actual Behavior
My Crud Repository is failing while performing operation with this error
Expected ID type to be the same as the return type of the hash key method ( class java.lang.String ) : class com.yantriks.yso.organization.services.core.dao.key.DynamoOrgKey",
***Key**
package com.yantriks.yso.organization.services.core.dao.key;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDocument; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; import com.yantriks.yso.external.db.support.DynamoKey;
import lombok.Data; import lombok.NoArgsConstructor;
@NoArgsConstructor @Data @DynamoDBDocument public class DynamoOrgKey implements DynamoKey{
}
**Entity
package com.yantriks.yso.organization.services.core.dao.entity;
import java.time.ZoneId;
import org.springframework.data.annotation.Id;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIgnore; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTypeConverted; import com.yantriks.yso.external.db.converters.ZoneIdConverterClass; import com.yantriks.yso.external.db.support.DynamoAuditGenericEntity; import com.yantriks.yso.organization.services.core.dao.key.DynamoOrgKey;
import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor;
@Data @AllArgsConstructor @NoArgsConstructor @DynamoDBTable(tableName = DynamoOrgEntity.TABLE_NAME) public class DynamoOrgEntity extends DynamoAuditGenericEntity{
}
package com.yantriks.yso.external.db.support;
import java.time.LocalDateTime;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDocument; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTypeConverted; import com.yantriks.yso.external.db.converters.LocalDateTimeConverterClass;
import lombok.Data;
@Data @DynamoDBDocument public abstract class DynamoAuditGenericEntity implements DynamoEntity {
private static final long serialVersionUID = -4217561694452434319L;
@DynamoDBAttribute(attributeName = "update_time") @DynamoDBTypeConverted(converter = LocalDateTimeConverterClass.class) protected LocalDateTime updateTime;
@DynamoDBAttribute(attributeName = "update_user") protected String updateUser; }
*****Repository*
package com.yantriks.yso.external.db.support;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.NoRepositoryBean;
@NoRepositoryBean public interface DynamoRepository<K extends DynamoKey,T extends DynamoEntity> extends CrudRepository<T,K> {
}
package com.yantriks.yso.external.db.repositories;
import org.socialsignin.spring.data.dynamodb.repository.EnableScan; import org.springframework.stereotype.Repository; import com.yantriks.yso.external.db.support.DynamoRepository; import com.yantriks.yso.organization.services.core.dao.entity.DynamoOrgEntity; import com.yantriks.yso.organization.services.core.dao.key.DynamoOrgKey;
@EnableScan @Repository public interface DynamoOrgRepository extends DynamoRepository<DynamoOrgKey, DynamoOrgEntity> {
}