Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore an entity field in Spring Data Cassandra?

How do I ignore an entity field in Spring Data Cassandra? Using the javax.persistence.Transient annotation?

like image 206
Ztyx Avatar asked Dec 04 '22 05:12

Ztyx


2 Answers

Try annotating your transient fields with org.springframework.data.annotation.Transient and report back whether that works.

So, I wrote a test adding three fields:

@javax.persistence.Transient
private Boolean one;
@org.springframework.data.annotation.Transient
private Boolean two;
private Boolean three;

to an entity to Cassandra. Result:

  • one was populated.
  • two was not populated.
  • three was populated. (just a check that I got my changes through)

Conclusion:

  • javax.persistence.Transient will not ignore a field.
  • org.springframework.data.annotation.Transient will ignore a field.

If it does, you get bonus points for creating a test for it and sending a pull request!

Sorry, I'm on a tight schedule and don't know the code well enough. Created a JIRA ticket, though!

like image 95
Ztyx Avatar answered Dec 06 '22 17:12

Ztyx


I don't recall explicitly coding this into spring-data-cassandra, but that behavior might just be provided entirely by spring-data-commons. I don't have time right now to create a test for that, though.

Try annotating your transient fields with org.springframework.data.annotation.Transient and report back whether that works. If it does, you get bonus points for creating a test for it and sending a pull request! :)

like image 23
Matthew Adams Avatar answered Dec 06 '22 18:12

Matthew Adams