POJO field having wrapper type, mapped to cassandra table are getting initialized to respective default value of primitive type instead of null if column value is null

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

POJO field having wrapper type, mapped to cassandra table are getting initialized to respective default value of primitive type instead of null if column value is null

kotamrajuyashasvi
This post was updated on .
Hi

I'm using ignite with cassandra as persistent store. I have a POJO class
mapped to cassandra table. I have used
ignite-cassandra-store/KeyValuePersistenceSettings xml bean to map POJO to
cassandra table. In the POJO one of the fields is Integer (wrapper class)
mapped to int column in cassandra table. When I load any row having this int
field as null in cassandra, I'm getting that respective field in POJO as 0,
which is default value of primitive type int. Same is the case when using
other wrapper classes. How can I get that field as null when the actual
column field is null in cassandra, since wrapper object can be null.

I found a work around by using custom class extending CacheStoreAdapter and
using this class in cache configuration in cacheStoreFactory
property,instead of using  ignite-cassandra-store. This class overrides
load,write and delete methods. In load method I connect to cassandra
database using Datastax driver, and load respective row depending upon the
key passed as parameter to load, and then create a new POJO whose fields are
set to the fields of row returned from cassandra and return the POJO. During
this process I make a check if the int field that I mentioned above is null
in cassandra by using Row.isNull method of Datastaxdriver and if its not
null only then I set POJO field to the field value returned from cassandra,
else it will remain as null.

Is it a bug in ignite-cassandra-store, where I cannot retain null value of
cassandra table field for primitive types mapped to wrapper classes in POJO
in ignite? The reason I have used wrapper class objects is to identify if
its null in cassandra or not, but there seems no way to differentiate
between primitive type default value and null when using
ignite-cassandra-store.

I found in the ignite source code that in org.apache.ignite.cache.store.cassandra.common.PropertyMappingHelper.getCassandraColumnValue(..) method there is no check being made to see if the column value is null or not for Integer,Float,Double,Long or Boolean. Here directly getInt,getFloat etc.. are called without making a check if the column value is null or not. From Datastax documentation we can see that getInt returns 0 if column value is null and similarly getLong returns 0L , getDouble return 0.0 etc.. But for String -> getString returns null if column value is null and also same for Date etc... Hence for primitive types I guess there should be an additional check to see if the column value is null.



--
Sent from: http://apache-ignite-developers.2346864.n4.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: POJO field having wrapper type, mapped to cassandra table are getting initialized to respective default value of primitive type instead of null if column value is null

dsetrakyan
Cross-sending to user@ as well.

On Tue, Sep 5, 2017 at 10:44 PM, kotamrajuyashasvi <
[hidden email]> wrote:

> Hi
>
> I'm using ignite with cassandra as persistent store. I have a POJO class
> mapped to cassandra table. I have used
> ignite-cassandra-store/KeyValuePersistenceSettings xml bean to map POJO to
> cassandra table. In the POJO one of the fields is Integer (wrapper class)
> mapped to int column in cassandra table. When I load any row having this
> int
> field as null in cassandra, I'm getting that respective field in POJO as 0,
> which is default value of primitive type int. Same is the case when using
> other wrapper classes. How can I get that field as null when the actual
> column field is null in cassandra, since wrapper object can be null.
>
> I found a work around by using custom class extending CacheStoreAdapter and
> using this class in cache configuration in cacheStoreFactory
> property,instead of using  ignite-cassandra-store. This class overrides
> load,write and delete methods. In load method I connect to cassandra
> database using Datastax driver, and load respective row depending upon the
> key passed as parameter to load, and then create a new POJO whose fields
> are
> set to the fields of row returned from cassandra and return the POJO.
> During
> this process I make a check if the int field that I mentioned above is null
> in cassandra by using Row.isNull method of Datastaxdriver and if its not
> null only then I set POJO field to the field value returned from cassandra,
> else it will remain as null.
>
> Is it a bug in ignite-cassandra-store, where I cannot retain null value of
> cassandra table field for primitive types mapped to wrapper classes in POJO
> in ignite? The reason I have used wrapper class objects is to identify if
> its null in cassandra or not, but there seems no way to differentiate
> between primitive type default value and null when using
> ignite-cassandra-store.
>
>
>
> --
> Sent from: http://apache-ignite-developers.2346864.n4.nabble.com/
>