Invalid INSERT created when mapping entity with boolean field #193

Closed
rickcole3 opened this Issue Mar 1, 2013 · 8 comments

Comments

Projects
None yet
4 participants

We are seeing a problem with entities mapped with boolean fields.We are seeing the following exception when trying to persist the entity:

InvalidRequestException(why:Invalid STRING constant (false) for read_only of type boolean)

I have traced this to the CQLTranslator.appendValue() method that creates the columnValues list. It appears that the value for the boolean is being wrapped in quotes which is causing cassandra to treat it as a string instead of a boolean. Are there plans to support mapping boolean fields to boolean columns? This seems to work if the column is text.

Collaborator

mevivs commented Mar 1, 2013

This is the case of Composite columns? I will look into this.

-Vivek

Thanks again for the quick response.

Yes. I am using Composite columns, but the field that is having the issue is not part of the composite key. I changed the column type to 'text', but it returns a value of 'true' every time. The reason I have found for this is due to the BooleanAccessor logic treating the value as 'true' unless it is of length zero or the first byte contains a 0. However, when the field is of type 'text', the value stored in the column is 'true' or 'false'. I put a breakpoint here and I see the data array contains 'false' but the value returned from this method is true.

public Boolean fromBytes(Class targetClass, byte[] data)
{
return (data == null || data.length == 0) ? false : data[0] != 0x00;
}

Collaborator

mevivs commented Mar 1, 2013

I will have a look and will update you. I guess the way cql treats with boolean type is as "true" and "false" so i might need to add a translation for this as well in CQL Translator or Accessor.

-Vivek

Collaborator

mevivs commented Mar 7, 2013

I have fixed this. Please verify it should be working fine.

-Vivek

mevivs added a commit that referenced this issue Mar 7, 2013

what is the resolution? even I am getting this error! my column is of type boolean and when trying to insert value as true or false it throws this error:

com.datastax.driver.core.exceptions.InvalidQueryException: Invalid STRING constant (true) for enabled of type boolean

Collaborator

mevivs commented Apr 9, 2013

Please have a look at:
https://github.com/impetus-opensource/Kundera/blob/trunk/kundera-cassandra/src/test/java/com/impetus/client/crud/compositeType/CompositeDataTypeTest.java

Here, PrimeUserDataType is holding a boolean variable. your cql script must have boolean as a datatype against such field.

Please verify your CRUD and entity definition against above mentioned junit.

-Vivek

Collaborator

mevivs commented Apr 9, 2013

This is release with 2.4

Contributor

xamry commented Apr 18, 2013

Can you please verify this and close?

@rickcole3 rickcole3 closed this Apr 22, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment