I created entity which is annotated with @Table
and it resembles my cassandra table. I can do save, get and everything without much problems.
My problem comes when I want to do something more exciting, like set consistency level or do if not exists insert or something like that. Basically there is annotation option for @Table
where you can configure read and write consistency but what if you use Spring and set that through configuration file? I really like having external configuration for those things. Also how to do if not exists save?
I know that you can get saveQuery
or getQuery
as Statement
and from it you can set consistency at least but it looks ugly, then you must take result set, do map and get your object.
Have two questions:
- Is there a better way of dynamically setting consistency level for object mapper actions both with accessor and entity?
- How to do if not exists save for mapped object?
I understand this a very old question. but some of the answers here are outdated hence, I am adding my answer here.
With driver version 4.x you can use the @StatementAttributes annotation to set the consistency level and other statement attributes for each of the mapper dao methods.