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:
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.
@Dao
public interface ProductDao {
@Select
@StatementAttributes(consistencyLevel = "ONE", pageSize = 500)
Product findById(int productId);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With