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

@PrimaryKeyColumn does not work when applied to methods [DATACASS-248] #424

Closed
spring-projects-issues opened this issue Jan 7, 2016 · 0 comments
Assignees
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug

Comments

@spring-projects-issues
Copy link

James Howe opened DATACASS-248 and commented

This code works:

public class Entity {
    
    @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED)
    private String col1;
    public String getCol1() { return col1; }
    
    @PrimaryKeyColumn(ordinal = 1)
    private String col2;
    public String getCol2() { return col2; }
    
}

This code doesn't:

public class Entity {
    
    private String col1;
    @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED)
    public String getCol1() { return col1; }
    
    private String col2;
    @PrimaryKeyColumn(ordinal = 1)
    public String getCol2() { return col2; }
    
}

Exception is:

java.lang.NullPointerException
	at org.springframework.data.cassandra.mapping.CassandraPrimaryKeyColumnAnnotationComparator.compare(CassandraPrimaryKeyColumnAnnotationComparator.java:46)
	at org.springframework.data.cassandra.mapping.CassandraPersistentPropertyComparator.compare(CassandraPersistentPropertyComparator.java:67)
	at org.springframework.data.cassandra.mapping.CassandraPersistentPropertyComparator.compare(CassandraPersistentPropertyComparator.java:29)
	at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
	at java.util.TimSort.sort(TimSort.java:220)
	at java.util.Arrays.sort(Arrays.java:1512)
	at java.util.ArrayList.sort(ArrayList.java:1454)
	at java.util.Collections.sort(Collections.java:175)
	at org.springframework.data.mapping.model.BasicPersistentEntity.verify(BasicPersistentEntity.java:382)
	at org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntity.verify(BasicCassandraPersistentEntity.java:196)
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:317)
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:276)
	at org.springframework.data.mapping.context.AbstractMappingContext.initialize(AbstractMappingContext.java:392)
	at org.springframework.data.cassandra.mapping.BasicCassandraMappingContext.initialize(BasicCassandraMappingContext.java:79)
	at org.springframework.data.mapping.context.AbstractMappingContext.afterPropertiesSet(AbstractMappingContext.java:382)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
	... 119 more

This becomes a particular problem when the Entity is in a class hierarchy, as methods can be overridden but fields cannot.


Affects: 1.3.2 (Gosling SR2)

Issue Links:

  • DATACASS-216 BasicCassandraPersistentProperty.isCompositePrimaryKey produces NPE when getField() returns null
    ("supersedes")

Referenced from: pull request #64

Backported to: 1.4.2 (Hopper SR2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants