Problem enabling read-through on cache - no suitable driver

classic Classic list List threaded Threaded
6 messages Options
Thomas Isaksen Thomas Isaksen
Reply | Threaded
Open this post in threaded view
|

Problem enabling read-through on cache - no suitable driver

I am trying to enable read-through on my cache as follows:

 

<bean id= "simpleDataSource" class="org.h2.jdbcx.JdbcDataSource"/>

 

<bean id="credentialsCacheTemplate" class="org.apache.ignite.configuration.CacheConfiguration">

                <property name="name" value="testCache"/>

                <property name="cacheMode" value="PARTITIONED"/>

                <property name="backups" value="1"/>

                <property name="readThrough" value="true"/>                                                                            

                <property name="cacheStoreFactory">

                               <bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">

                                               <property name="dataSourceBean" value="simpleDataSource" />

                               </bean>

                </property>

</bean>

 

Once I activate my cluster I get this error message:

 

SEVERE: Failed to initialize cache. Will try to rollback cache start routine. [cacheName=testCache]

class org.apache.ignite.IgniteCheckedException: Failed to start component: javax.cache.CacheException: Failed access to metadata for detect database dialect.

        at org.apache.ignite.internal.util.IgniteUtils.startLifecycleAware(IgniteUtils.java:8757)

        at org.apache.ignite.internal.processors.cache.GridCacheProcessor.createCache(GridCacheProcessor.java:1344)

        at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCacheStart(GridCacheProcessor.java:1799)

        at org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager.onCacheChangeRequest(CacheAffinitySharedManager.java:751)

        at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.onClusterStateChangeRequest(GridDhtPartitionsExchangeFuture.java:817)

        at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.init(GridDhtPartitionsExchangeFuture.java:583)

        at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:2279)

        at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)

        at java.lang.Thread.run(Thread.java:745)

Caused by: javax.cache.CacheException: Failed access to metadata for detect database dialect.

        at org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore.resolveDialect(CacheAbstractJdbcStore.java:273)

        at org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore.start(CacheAbstractJdbcStore.java:305)

        at org.apache.ignite.internal.util.IgniteUtils.startLifecycleAware(IgniteUtils.java:8753)

        ... 8 more

Caused by: java.sql.SQLException: No suitable driver found for

        at org.h2.jdbcx.JdbcDataSource.getJdbcConnection(JdbcDataSource.java:190)

        at org.h2.jdbcx.JdbcDataSource.getConnection(JdbcDataSource.java:159)

        at org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore.openConnection(CacheAbstractJdbcStore.java:325)

        at org.apache.ignite.cache.store.jdbc.CacheAbstractJdbcStore.resolveDialect(CacheAbstractJdbcStore.java:268)

        ... 10 more

 

 

I can see that there is a message “No suitable driver found for ..” but shouldn’t the H2 driver already be on the Ignite classpath already? If not, how do I fix it?

 

Regards

Thomas Isaksen

slava.koptilin slava.koptilin
Reply | Threaded
Open this post in threaded view
|

Re: Problem enabling read-through on cache - no suitable driver

Hi Thomas,

Please make sure that your h2 database is started and required tables are
created.
You can use the following test as example how to do that (please see,
CacheJdbcPojoStoreAbstractSelfTest#beforeTest)
https://github.com/apache/ignite/blob/master/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreAbstractSelfTest.java

Cache configuration should be modified as well.

1. First of all, correct DB connection URL should be provided. For instance,
    <bean id="simpleDataSource" class="org.h2.jdbcx.JdbcDataSource">
        <property name="URL"
value="jdbc:h2:mem:TestDatabase;DB_CLOSE_DELAY=-1"/>
        <property name="user" value="username"/>
        <property name="password" value=""/>
    </bean>

2. secondly, you need to configure types mapping within the cache
configuration. Let's assume that you have a simple cache
IgniteCache<Integer, String>
    <bean class="org.apache.ignite.configuration.CacheConfiguration">
        <property name="name" value="test-cache"/>
        <property name="readThrough" value="true"/>
        <property name="writeThrough" value="true"/>

        <property name="cacheStoreFactory">
            <bean
class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">
                <property name="dataSourceBean" value="storeDataSource"/>

                <property name="dialect">
                    <bean
class="org.apache.ignite.cache.store.jdbc.dialect.H2Dialect"/>
                </property>

                <property name="types">
                    <list>
                        <bean
class="org.apache.ignite.cache.store.jdbc.JdbcType">
                            <property name="cacheName" value="test-cache"/>
                            <property name="keyType"
value="java.lang.Integer"/>
                            <property name="valueType"
value="java.lang.String"/>
                            <property name="databaseSchema" value="PUBLIC"/>
                            <property name="databaseTable"
value="testtable"/>

                            <property name="keyFields">
                                <list>
                                    <bean
class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
                                        <property name="databaseFieldName"
value="ID"/>
                                        <property name="databaseFieldType">
                                            <util:constant
static-field="java.sql.Types.INTEGER"/>
                                        </property>
                                        <property name="javaFieldName"
value="id"/>
                                        <property name="javaFieldType"
value="java.lang.Integer"/>
                                    </bean>
                                </list>
                            </property>

                            <property name="valueFields">
                                <list>
                                    <bean
class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
                                        <property name="databaseFieldName"
value="name"/>
                                        <property name="databaseFieldType">
                                            <util:constant
static-field="java.sql.Types.VARCHAR"/>
                                        </property>
                                        <property name="javaFieldName"
value="name"/>
                                        <property name="javaFieldType"
value="java.lang.String"/>

                                    </bean>
                                </list>
                            </property>
                        </bean>
                    </list>
                </property>
            </bean>
        </property>
    </bean>

additional example(s) can be found here:
https://github.com/apache/ignite/blob/master/modules/spring/src/test/config/jdbc-pojo-store-builtin.xml

Thanks,
Slava.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Thomas Isaksen Thomas Isaksen
Reply | Threaded
Open this post in threaded view
|

RE: Problem enabling read-through on cache - no suitable driver

Hi Slava,

Thank you so much for your reply it is most helpful!

I'm a little confused by all of this because I have been connecting with DBeaver to jdbc:ignite:thin://127.0.0.1/ and I can create tables there if I use the predefined templates PARTITIONED or REPLICATED, however, when I try using my own templates I simply get SQL Error[50000] "Cache doesn't exist!" - not sure why this is happening but maybe I'm not connecting to the right DB?

Is the jdbc:ignite:thin connection not a connection to the H2 instance used by Ignite internally? Is it not "legit" to use this instance to create my tables or do I have to use another database?


./t

-----Original Message-----
From: slava.koptilin [mailto:[hidden email]]
Sent: torsdag 11. januar 2018 17.26
To: [hidden email]
Subject: Re: Problem enabling read-through on cache - no suitable driver

Hi Thomas,

Please make sure that your h2 database is started and required tables are created.
You can use the following test as example how to do that (please see,
CacheJdbcPojoStoreAbstractSelfTest#beforeTest)
https://github.com/apache/ignite/blob/master/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreAbstractSelfTest.java

Cache configuration should be modified as well.

1. First of all, correct DB connection URL should be provided. For instance,
    <bean id="simpleDataSource" class="org.h2.jdbcx.JdbcDataSource">
        <property name="URL"
value="jdbc:h2:mem:TestDatabase;DB_CLOSE_DELAY=-1"/>
        <property name="user" value="username"/>
        <property name="password" value=""/>
    </bean>

2. secondly, you need to configure types mapping within the cache configuration. Let's assume that you have a simple cache IgniteCache<Integer, String>
    <bean class="org.apache.ignite.configuration.CacheConfiguration">
        <property name="name" value="test-cache"/>
        <property name="readThrough" value="true"/>
        <property name="writeThrough" value="true"/>

        <property name="cacheStoreFactory">
            <bean
class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">
                <property name="dataSourceBean" value="storeDataSource"/>

                <property name="dialect">
                    <bean
class="org.apache.ignite.cache.store.jdbc.dialect.H2Dialect"/>
                </property>

                <property name="types">
                    <list>
                        <bean
class="org.apache.ignite.cache.store.jdbc.JdbcType">
                            <property name="cacheName" value="test-cache"/>
                            <property name="keyType"
value="java.lang.Integer"/>
                            <property name="valueType"
value="java.lang.String"/>
                            <property name="databaseSchema" value="PUBLIC"/>
                            <property name="databaseTable"
value="testtable"/>

                            <property name="keyFields">
                                <list>
                                    <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
                                        <property name="databaseFieldName"
value="ID"/>
                                        <property name="databaseFieldType">
                                            <util:constant static-field="java.sql.Types.INTEGER"/>
                                        </property>
                                        <property name="javaFieldName"
value="id"/>
                                        <property name="javaFieldType"
value="java.lang.Integer"/>
                                    </bean>
                                </list>
                            </property>

                            <property name="valueFields">
                                <list>
                                    <bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
                                        <property name="databaseFieldName"
value="name"/>
                                        <property name="databaseFieldType">
                                            <util:constant static-field="java.sql.Types.VARCHAR"/>
                                        </property>
                                        <property name="javaFieldName"
value="name"/>
                                        <property name="javaFieldType"
value="java.lang.String"/>

                                    </bean>
                                </list>
                            </property>
                        </bean>
                    </list>
                </property>
            </bean>
        </property>
    </bean>

additional example(s) can be found here:
https://github.com/apache/ignite/blob/master/modules/spring/src/test/config/jdbc-pojo-store-builtin.xml

Thanks,
Slava.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
slava.koptilin slava.koptilin
Reply | Threaded
Open this post in threaded view
|

RE: Problem enabling read-through on cache - no suitable driver

Hi Thomas,

> however, when I try using my own templates I simply get SQL Error[50000]
> "Cache doesn't exist!"
>- not sure why this is happening but maybe I'm not connecting to the right
DB?
Could you please provide us with the template you are trying to use?

> Is the jdbc:ignite:thin connection not a connection to the H2 instance
> used by Ignite internally?
No, jdbc:ignite:thin is not a connection to the underlying H2 db. This is a
thin driver which is used to connect to Ignite node and allows processing
distributed data using Ignite cluster. Please see the following page for
details [1]

[1] https://apacheignite-sql.readme.io/docs/jdbc-driver#jdbc-thin-driver

Thanks,
Slava.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Thomas Isaksen Thomas Isaksen
Reply | Threaded
Open this post in threaded view
|

RE: Problem enabling read-through on cache - no suitable driver

Hi Slava,

Ok great that clears up things quite a bit for me.
The template I am trying to use is shown in my latest post:

http://apache-ignite-users.70518.x6.nabble.com/SQL-Error-Failed-to-query-Ignite-tp19475.html

Thanks!
./t

-----Original Message-----
From: slava.koptilin [mailto:[hidden email]]
Sent: mandag 15. januar 2018 11.42
To: [hidden email]
Subject: RE: Problem enabling read-through on cache - no suitable driver

Hi Thomas,

> however, when I try using my own templates I simply get SQL
>Error[50000]  "Cache doesn't exist!"
>- not sure why this is happening but maybe I'm not connecting to the
>right
DB?
Could you please provide us with the template you are trying to use?

> Is the jdbc:ignite:thin connection not a connection to the H2 instance
> used by Ignite internally?
No, jdbc:ignite:thin is not a connection to the underlying H2 db. This is a thin driver which is used to connect to Ignite node and allows processing distributed data using Ignite cluster. Please see the following page for details [1]

[1] https://apacheignite-sql.readme.io/docs/jdbc-driver#jdbc-thin-driver

Thanks,
Slava.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
slava.koptilin slava.koptilin
Reply | Threaded
Open this post in threaded view
|

RE: Problem enabling read-through on cache - no suitable driver

Hi,

please see my answer to that thread. I hope it solves the issue.

Thanks!



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/