kundera icon indicating copy to clipboard operation
kundera copied to clipboard

can null value be set by using jpql when cassandra?

Open zhouhero opened this issue 13 years ago • 24 comments

i want to update table's column to null value by using jpql . how can i do it? my db is cassandra.

zhouhero avatar Jan 22 '13 06:01 zhouhero

There is nothing like null in cassandra as everything has a byte[] representation. What you could do is to set explicitly as "null" string value and handle it in your application by string equals comparision with "null" !

-Vivek

mevivs avatar Jan 22 '13 06:01 mevivs

yes, iee.

by the way, when entity saving, if i set the property to null,the column can be set to nothing?

sample:

entity.setName(null); em.persist()entity;

zhouhero avatar Jan 22 '13 07:01 zhouhero

can i clear the column's data by the up actions?

zhouhero avatar Jan 22 '13 07:01 zhouhero

Yes, by default Kundera omit such columns. But if you try: entity.setName("null"); // null as string.

It should work for you.

mevivs avatar Jan 22 '13 07:01 mevivs

"can i clear the column's data by the up actions? "

Can you please explain more on this?

-Vivek

mevivs avatar Jan 22 '13 07:01 mevivs

entity.setName("null"); →it will help me clear the data value in name column of the table?

zhouhero avatar Jan 22 '13 07:01 zhouhero

others, when i set UUID column to null like fellowing, the column not be update to null in db.

entity.setId(null);//Id is UUID type

zhouhero avatar Jan 22 '13 08:01 zhouhero

As i mentioned earlier, null and "null" are two different assignment. if you assign null, it won't be persisted, as cassandra does not understand a null. But if you assign it a value as "null", which is essentially a string value. It will work. Now for UUID type, it is not of String type. So i recommend, if you want to store your row key as "null" ! ( Which is highly unlikely not permissible in RDBMS even), then change your data type to UTF8Type from UUIDType.

-Vivek

mevivs avatar Jan 22 '13 08:01 mevivs

yes, i see.

but in cql , like "delete from "can clear the data of the cloumn. how can do the same thing by using jpql?

zhouhero avatar Jan 22 '13 08:01 zhouhero

yes, i see.

but in cql , like "delete columnName from tableName"can clear the data of the cloumn. how can do the same thing by using jpql?

zhouhero avatar Jan 22 '13 08:01 zhouhero

Simply invoke, for example;

Delete p from Person P;

Have a look at: https://github.com/impetus-opensource/Kundera/blob/trunk/kundera-cassandra/src/test/java/com/impetus/client/persistence/UpdateDeleteNamedQueryTest.java

for reference.

-Vivek

mevivs avatar Jan 22 '13 08:01 mevivs

in the sample, the full row (entity) is deleted. i just want to delete some columns of the row. how can i do it in jpql?

http://cassandra.apache.org/doc/cql/CQL.html#DELETE

zhouhero avatar Jan 22 '13 08:01 zhouhero

Thrift API does not support it. Only possible way is via executing CQL query, which is via em.createNativeQuery.

-Vivek

mevivs avatar Jan 22 '13 08:01 mevivs

in new verion of kundera 2.3,i think i can use jdbc driver, when i use jdbc driver, can i do it ?

zhouhero avatar Jan 22 '13 08:01 zhouhero

as you know, if i use jpql and cql in the application, there may be have some problems when update data.

pls refer: https://github.com/impetus-opensource/Kundera/issues/154

zhouhero avatar Jan 22 '13 08:01 zhouhero

Still cassandra jdbc driver is not very mature and set of features supported by Kundera simply may not work using JDBC. So we are planning it for 2.4

However, 2.3 release will be upgraded to cassandra 1.2 for thrift API. Also other issues raised around usage "update query with set parameter" and "support of count in JPQL" will be in with 2.3

-Vivek

mevivs avatar Jan 22 '13 08:01 mevivs

thanks for your infos!

others, in Thrift API , i think the sepc clomns can be removed.

sample: http://abel-perez.com/cassandra-delete-column-example

zhouhero avatar Jan 22 '13 09:01 zhouhero

Hmm. Looks like i missed on it then. keeping it open for 2.4

-Vivek

mevivs avatar Jan 22 '13 09:01 mevivs

thank you very much! by the way, when kundera 2.4 will release? can you tell me your plan?

zhouhero avatar Jan 22 '13 09:01 zhouhero

We did not finalize on date yet. But should be in a month or so.

I guess as an alternative, still you can use CQL native query support to achieve such features via Kundera

-Vivek

mevivs avatar Jan 22 '13 09:01 mevivs