Cannot persist data in Cassandra using Kundera

437 views Asked by At

I tried to connect to cassadra and perform CRUD operation from this link. But after executing the code got the below exception.Can't figure out the problem.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Jun 29, 2015 2:47:00 PM com.impetus.client.cassandra.config.CassandraPropertyReader onProperties
WARNING: No property file found in class path, kundera will use default property
Jun 29, 2015 2:47:01 PM com.impetus.kundera.persistence.EntityManagerFactoryImpl <init>
INFO: EntityManagerFactory created for persistence unit : kundera
Exception in thread "main" com.impetus.kundera.KunderaException: org.scale7.cassandra.pelops.exceptions.NoConnectionsAvailableException: Failed to get a connection within the configured max wait time.
    at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:208)
    at kundera.KunderaClient.main(KunderaClient.java:22)
Caused by: org.scale7.cassandra.pelops.exceptions.NoConnectionsAvailableException: Failed to get a connection within the configured max wait time.
    at org.scale7.cassandra.pelops.pool.CommonsBackedPool.getConnectionExcept(CommonsBackedPool.java:345)
    at org.scale7.cassandra.pelops.Operand.tryOperation(Operand.java:77)
    at org.scale7.cassandra.pelops.Mutator.execute(Mutator.java:93)
    at org.scale7.cassandra.pelops.Mutator.execute(Mutator.java:63)
    at com.impetus.client.cassandra.pelops.PelopsClient.onPersist(PelopsClient.java:527)
    at com.impetus.kundera.client.ClientBase.persist(ClientBase.java:83)
    at com.impetus.kundera.lifecycle.states.ManagedState.handleFlush(ManagedState.java:193)
    at com.impetus.kundera.graph.Node.flush(Node.java:525)
    at com.impetus.kundera.persistence.PersistenceDelegator.flush(PersistenceDelegator.java:411)
    at com.impetus.kundera.persistence.PersistenceDelegator.persist(PersistenceDelegator.java:169)
    at com.impetus.kundera.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:202)
    ... 1 more

However, I can perform crud operation from cqlsh.

Below is my persistence.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="kundera">
        <provider>com.impetus.kundera.KunderaPersistence</provider>
        <class>kundera.Catalog</class>
        <properties>
            <property name="kundera.nodes" value="localhost" />
            <property name="kundera.port" value="9042" />
            <property name="kundera.username" value="cassandra" />
            <property name="kundera.passsword" value="cassandra" />
            <property name="kundera.keyspace" value="Kundera" />
            <property name="kundera.dialect" value="cassandra" />
            <property name="kundera.client.lookup.class"
                value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />
            <property name="kundera.cache.provider.class"
                value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
            <property name="kundera.cache.config.resource" value="/ehcache-test.xml" />
        </properties>
    </persistence-unit>
</persistence>

I tried changing kundera.port to 9160. But got the same exception.

2

There are 2 answers

0
Chhavi Gangwal On

Is your Cassandra server enabled for authentication ? Which version of kundera-cassandra are you using ? Also, can you please update your persistence.xml and try with :

<persistence-unit name="kundera">
    <provider>com.impetus.kundera.KunderaPersistence</provider>
    <class>kundera.Catalog</class>
    <properties>
        <property name="kundera.nodes" value="localhost" />
        <property name="kundera.port" value="9160" />
        <property name="kundera.username" value="cassandra" />
        <property name="kundera.passsword" value="cassandra" />
        <property name="kundera.keyspace" value="Kundera" />
        <property name="kundera.dialect" value="cassandra" />
        <property name="kundera.client.lookup.class"
            value="com.impetus.client.cassandra.thrift.ThriftClientFactory" />

    </properties>
</persistence-unit>

1
vivek mishra On

9042 port is for cql3 binary protocol enabled clients but not the thrift clients. Change,

<property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />

TO

<property name="kundera.client.lookup.class" value="com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory" />

it should work for you.

HTH, -Vivek