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 empty collection-typed properties overwrites pre-initialized fields [DATACASS-266] #439

Open
spring-projects-issues opened this issue Apr 4, 2016 · 3 comments
Assignees
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug

Comments

@spring-projects-issues
Copy link

Mark Paluch opened DATACASS-266 and commented

Cassandra list/set typed columns represent an empty collection as null. From here one can't tell whether the state was null or empty at the time saving the value. Loading this value causes MappingCassandraConverter to overwrite pre-initialized fields (e.g. with new ArrayList) with null.


Affects: 1.3.4 (Gosling SR4)

Reference URL: http://stackoverflow.com/questions/36349896/how-can-i-ensure-cassandraoperations-selectonebyid-initializes-all-fields-in-t

1 votes, 4 watchers

@spring-projects-issues
Copy link
Author

Paweł Stawicki commented

Some solution could be to set the property via setter, not directly setting an entity field. This way null could be handled in setter by entity author

@spring-projects-issues
Copy link
Author

Mark Paluch commented

You can achieve property accessor use by specifying @AccessType(PROPERTY) on class/property level

@spring-projects-issues
Copy link
Author

Scott Lehman commented

There is also the option of handling the null in a constructor that Spring Data uses to instantiate the model.  The reference guide actually recommends using an all argument constructor, and if you make the model immutable (also a recommendation), there's no need to also provide a setter.

A constructor approach does require a bit more care, so it's important to fully understand the requirements documented in the reference guide (see the "Object Mapping Fundamentals" section), and you can't simply rely on Lombok's @AllArgsConstructor, which makes the property access approach a bit simpler in terms of implementation/maintenance

@spring-projects-issues spring-projects-issues added type: bug A general bug in: mapping Mapping and conversion infrastructure labels Dec 31, 2020
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