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

Loading Enums using their ordinal fails [DATACASS-652] #800

Closed
spring-projects-issues opened this issue May 4, 2019 · 3 comments
Closed
Assignees
Labels
in: kotlin in: mapping type: bug

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented May 4, 2019

Tobias Hermann opened DATACASS-652 and commented

Persisting enums as ordinals not working, uses string instead of int in statement

According to Example 1. Enum mapping to numeric types from the spring-data-cassandra-mapping documentation (https://github.com/spring-projects/spring-data-cassandra/blob/master/src/main/asciidoc/reference/mapping.adoc) the attached minimal example should be able to store and retrieve enums as ordinals to and from Cassandra.

But when running ./gradlew test, the following error occurs:

{{enumtest.PersistenceTest > test save FAILED}}
{{ org.springframework.data.cassandra.CassandraInvalidQueryException: SessionCallback; CQL [INSERT INTO thing (thingid,some) VALUES (1,'FOO');]; Expected 4 or 0 byte int (3); nested exception is com.datastax.driver.core.exceptions.InvalidQueryException: Expected 4 or 0 byte int (3)}}

So, it incorrectly tries to persist the enum as string ('FOO') foo, despite having the following annotation: @CassandraType(type = DataType.Name.INT)

 


Affects: 2.1.6 (Lovelace SR6)

Reference URL: https://stackoverflow.com/questions/55915849/how-to-persist-enums-as-ordinals-with-spring-boot-and-cassandra/55978992#55978992

Attachments:

Backported to: 2.1.7 (Lovelace SR7)

@spring-projects-issues
Copy link
Author

spring-projects-issues commented May 5, 2019

Mark Paluch commented

The code works when using Java classes. For some reason, the Kotlin class does not report @CassandraType on the field some. Switching to Java allows persisting. However, during loading, the enum value cannot be restored because we do not consider the value type when loading the enum. That's something we need to fix

@spring-projects-issues
Copy link
Author

spring-projects-issues commented May 5, 2019

@spring-projects-issues
Copy link
Author

spring-projects-issues commented May 5, 2019

Mark Paluch commented

The loading issue is solved now. We cannot do anything about the annotation visibility. You might want to file a report a bug at https://youtrack.jetbrains.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: kotlin in: mapping type: bug
Projects
None yet
Development

No branches or pull requests

2 participants