kundera icon indicating copy to clipboard operation
kundera copied to clipboard

Operator IN

Open sachur opened this issue 13 years ago • 6 comments

When use "in" key word using cassandra 1.2 (kundera 2.5) with the next query, for example:

Query query = em.createQuery("SELECT * FROM ColumnFamily where KEY IN ( 12345,123456); query.getResultList();

The following error happend: "Condition in is not suported for query on row key! "

Can anyone help me get it working ? Thanks

sachur avatar May 22 '13 14:05 sachur

Hi, Currently Kundera does not support IN clause in JPQL way(work in progress). But you can execute a native cql3 query as:

Query query = em.createNativeQuery("SELECT * FROM ColumnFamily where KEY IN ( 12345,123456)"); query.getResultList();

-Vivek

I used createNativeQuery, and the following error happend:

InvalidRequestException(why:Cannot execute/prepare CQL3 statement since the CQL has been set to CQL2(This might mean your client hasn't been upgraded correctly to use the new CQL3 methods introduced in Cassandra 1.2+)

I've been researching on the error but have not found anything useful. Any help? Thanks

sachur avatar May 22 '13 16:05 sachur

You need to set for cql version to 3.0.0 . Given below are various ways to set this.

  1. You can set it while creating entity manager factory as:
        propertyMap = new HashMap();
        propertyMap.put(CassandraConstants.CQL_VERSION, CassandraConstants.CQL_VERSION_3_0);
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(persisntenceUnit, propertyMap);

  1. Another alternative is, set it via Em as
        Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();
        ThriftClient tc = (ThriftClient) clientMap.get("your pu name");
        tc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);
  1. Else you can also pass it as property as, create a property file(say, kunderaTest.xml:
<?xml version="1.0" encoding="UTF-8"?>
<clientProperties>
    <datastores>
        <dataStore>
            <name>cassandra</name>
            <connection>
                <properties>
                                         <property name="cql.version" value="3.0.0"></property>
                </properties>
            </connection>
        </dataStore>
    </datastores>
</clientProperties>

And then configure it in persistence.xml as:

            <property name="kundera.client.property" value="kunderaTest.xml" />

Hope it helps.

-Vivek

mevivs avatar May 22 '13 16:05 mevivs

Is this working for you?

-Vivek

mevivs avatar May 23 '13 09:05 mevivs

Yes, it has worked. Thank you very much for helping

sachur avatar May 23 '13 10:05 sachur

Ok. Great!

Using Kundera for?

-Vivek

mevivs avatar May 23 '13 10:05 mevivs