How spring data Cassandra handles null while saving - spring-boot

I have a spring boot application with spring-boot-starter-data-cassandra of version-2.1.2.RELEASE.
Need to understand how spring data Cassandra internally handles null in entity while performing insert option.
Using AsyncCassandraOperations.insert(<T>) method for persisting these entities. In some cases these entity's few fields may be null. Is this approach impact Cassandra performance or tombstones may create in Cassandra. Or please suggest an ideal approach.

There are no issues if some of the individual fields of an object are null. There are problems if one of the fields that comprise the key is null.

Related

Best practice for combining database with object store in Spring Boot App

I've an application which stores entites in MariaDB. The entity has some relations to other entities and in one of the child entities is a binary attribute. See the following:
Parent
\ 1-n ChildA
- attrA1
- ...
\ 1-n ChildB
- attrB1
- binaryAttr
Storing the binary files in the DB has an impact on the DB size of course and thereby an impact on our backup concept. Besides this binary data doesn't necessarily have to be in the DB as well.
I'm thinking about combining MariaDB with an S3 compatible object store, so that the structured data is persisted in DB and the binary files in the object store.
We're are using Spring Boot (Data-JPA) with Apache Camel.
The naïve approach would be to store the binary file with a uuid-key in the object store and afterwards persisting the rest of the entity with the reference (uuid) to the DB.
But there's no easy transaction handling for this, nor a transparent handling of the entity (I've to handle persisting entity and binary data seperately).
Is there a java / spring based framework to overcome the drawbacks (transaction handling, transparent handling) of two different "datasources"?
What is the best practice to handle such a scenario or is it totally unrecommended?
Is there an extension mechanism for Spring / Hibernate to handle object store persistency within the hibernate orm mapping process?
Is it possible to implement one repository for persisting / loading entity and binary data at once?
Can anyone give me some direction?

Spring Boot Rest API + JPA

I have a CRUD based application, which uses Spring Boot REST Services and JPA. For JPA we have POJO objects mapped to RBMS - PostgreSQL.
Some of my pages require data to be fetched using joins of multiple POJO objects. I just wanted to know what is a good architectural practice to do the same. Following are some of the options i have been informed of, but not sure what are the pros and cons of each especially for a large data volume application.
Use Transient Variables in POJOs and use JPA joins
Use additional Spring View Objects to combine POJOs
Write native/HQL to join tables/POJOs
Any insight would be helpful. If any more details required from me, would be glad to provide.
I think it's better to go with Entity Mappings.
This will enable you to easily fetch the parent and its nested entities using either JPA methods or using hibernate.
You can also specify the fetch type to actually control the behaviour of this fetch.
In case, you are looking for any complex joins or fetch patterns, Entity Graphs and HQL will be very useful.

Spring-boot + Ignite create null value tombstones in cassandra

I'm using cassandra as the 3rd party store for Ignite. For persisting data to Ignite I use spring-boots ignite-jpa implementation and my objects often have fields that are not populated and therefore null. Naturally when the data is persisted into cassandra, this creates a null value tombstone(s) and in my case quite many due to the volume of data.
Does anyone know if there is a configuration where I could specify not to set (unset) fields (columns) with null value during insert?
I'm aware that null value in cassandra has a special meaning and that this approach would end up not overriding a column value in case of an update to null. However, I'm not concerned with that case.
What I did so far, was to implement my custom CassandraCacheStoreFactory, but was wandering if there is a simpler way.
If you insert null value, there is no way on cluster side to tell Cassandra to ignore it.
But on client side, with your driver you can tell it to ignore null values so it won't send it to Cassandra.
Take a look at InsertOptions.InsertOptionsBuilder there is a method that tells the driver to ignore null value : withInsertNulls(boolean insertNulls), I think it fits for your use case :
https://docs.spring.io/spring-data/cassandra/docs/current/api/org/springframework/data/cassandra/core/InsertOptions.InsertOptionsBuilder.html#withInsertNulls-boolean-

Generic Entity in Spring Data for Couchbase Documents

One advantage of Document DBs like Couchbase is schemaless entities. It gives me freedom to add new attributes within the document without any schema change.
Using Couchbase JsonObject and JsonDocument my code remains generic to perform CRUD operations without any need to modify it whenever new attribute is added to the document. Refer this example where no Entities are created.
However if I follow the usual Spring Data approach of creating Entity classes, I do not take full advantage of this flexibility. I will end up in code change whenever I add new attribute into my document.
Is there a approach to have generic entity using Spring Data? Or Spring Data is not really suitable for schemaless DBs? Or is my understanding is incorrect?
I would argue the opposite is true.
One way or another if you introduce a new field you have to handle the existing data that doesn't have that field.
Either you update all your documents to include that field. That is what schema based stores basically force you to do.
Or you leave your store as it is and let your application handle that issue. With Spring Data you have some nice and obvious ways to handle that in a consistent fashion, e.g. by having a default value in the entity or handling that in a listener.

Does Spring data Neo4j support schema-less property?

The nosql database has schema-less property, so we could add any fields/properties to nodes or relationship. But If I use spring data as the framework, I have to pre-define the field of nodes and relationship object. It seem Spring data Neo4j not support inserting field dynamically...Is it true?
It most definitely supports dynamically inserting fields.
Just update your POJOs with the appropriate fields/annotations, run it, and enjoy the magic!
To recap:
Update your POJOs whenever you need with whatever fields and annotations.
Run your project.
Profit.
If you are using Spring Data Neo4j version 3, then DynamicProperties will probably fulfill your needs.
However, in version 4 it has not yet been implemented see this discussion.

Resources