19.6. JDBC Based Cache Stores


Red Hat JBoss Data Grid offers several cache stores for use with common data storage formats. JDBC based cache stores are used with any cache store that exposes a JDBC driver. JBoss Data Grid offers the following JDBC based cache stores depending on the key to be persisted:
  • JdbcBinaryStore.
  • JdbcStringBasedStore.
  • JdbcMixedStore.

19.6.1. JdbcBinaryStores

The JdbcBinaryStore supports all key types. It stores all keys with the same hash value (hashCode method on the key) in the same table row/blob. The hash value common to the included keys is set as the primary key for the table row/blob. As a result of this hash value, JdbcBinaryStore offers excellent flexibility but at the cost of concurrency and throughput.
As an example, if three keys (k1, k2 and k3) have the same hash code, they are stored in the same table row. If three different threads attempt to concurrently update k1, k2 and k3, they must do it sequentially because all three keys share the same row and therefore cannot be simultaneously updated.
The following is a configuration for JdbcBinaryStore using Red Hat JBoss Data Grid's Remote Client-Server mode with Passivation enabled:
<local-cache name="customCache">
	
	<!-- Additional configuration elements here -->
	<binary-keyed-jdbc-store datasource="java:jboss/datasources/JdbcDS" 
	
				 passivation="${true/false}" 
				 preload="${true/false}" 
				 purge="${true/false}">
               	<binary-keyed-table prefix="JDG">
               		<id-column name="id" 
				   type="${id.column.type}"/>
               		<data-column name="datum" 
				     type="${data.column.type}"/>
              		<timestamp-column name="version" 
					  type="${timestamp.column.type}"/>
              	</binary-keyed-table>
       	</binary-keyed-jdbc-store>
</local-cache>
Copy to Clipboard Toggle word wrap
For details about the elements and parameters used in this sample configuration, see Section 19.3, “Cache Store Configuration Details (Remote Client-Server Mode)”.
The following is a sample configuration for the JdbcBinaryStore:
<infinispan
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:infinispan:config:8.3 http://www.infinispan.org/schemas/infinispan-config-8.3.xsd
            urn:infinispan:config:store:jdbc:8.0 http://www.infinispan.org/schemas/infinispan-cachestore-jdbc-config-8.0.xsd"
        xmlns="urn:infinispan:config:8.3">
        <!-- Additional configuration elements here -->
	<persistence>
	<binary-keyed-jdbc-store xmlns="urn:infinispan:config:store:jdbc:8.0
                              fetch-state="false"
			      purge="false">
		<connection-pool connection-url="jdbc:h2:mem:infinispan_binary_based;DB_CLOSE_DELAY=-1" 
				username="sa" 
				driver="org.h2.Driver"/>
		<binary-keyed-table dropOnExit="true" 
				  createOnStart="true" 
				  prefix="ISPN_BUCKET_TABLE">
			<id-column name="ID_COLUMN" 
				  type="VARCHAR(255)" />
			<data-column name="DATA_COLUMN" 
				    type="BINARY" />
			<timestamp-column name="TIMESTAMP_COLUMN" 
					 type="BIGINT" />
		</binary-keyed-table>
	</binary-keyed-jdbc-store>
</persistence>
Copy to Clipboard Toggle word wrap
For details about the elements and parameters used in this sample configuration, see Section 19.2, “Cache Store Configuration Details (Library Mode)”.

19.6.2. JdbcStringBasedStores

The JdbcStringBasedStore stores each entry in its own row in the table, instead of grouping multiple entries into each row, resulting in increased throughput under a concurrent load. It also uses a (pluggable) bijection that maps each key to a String object. The key-to-string-mapper interface defines the bijection.
Red Hat JBoss Data Grid includes a default implementation called DefaultTwoWayKey2StringMapper that handles primitive types.
The following is a sample JdbcStringBasedStore for Red Hat JBoss Data Grid's Remote Client-Server mode:
<local-cache name="customCache">
	<!-- Additional configuration elements here -->
	<string-keyed-jdbc-store datasource="java:jboss/datasources/JdbcDS" 
				 passivation="true" 
				 preload="false" 
				 purge="false"
				 shared="false"
				 singleton="true">
               	<string-keyed-table prefix="JDG">
               		<id-column name="id" 
				   type="${id.column.type}"/>
			<data-column name="datum" 
				     type="${data.column.type}"/>
			<timestamp-column name="version" 
					  type="${timestamp.column.type}"/>
	        </string-keyed-table>
	</string-keyed-jdbc-store>
</local-cache>
Copy to Clipboard Toggle word wrap
For details about the elements and parameters used in this sample configuration, see Section 19.3, “Cache Store Configuration Details (Remote Client-Server Mode)”.
The following is a sample configuration for the JdbcStringBasedStore:
<infinispan
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:infinispan:config:8.3 http://www.infinispan.org/schemas/infinispan-config-8.3.xsd
            urn:infinispan:config:store:jdbc:8.0 http://www.infinispan.org/schemas/infinispan-cachestore-jdbc-config-8.0.xsd"
        xmlns="urn:infinispan:config:8.3">
        <!-- Additional configuration elements here -->
	<persistence>
	<string-keyed-jdbc-store xmlns="urn:infinispan:config:store:jdbc:8.0"
	                      fetch-state="false"
			      purge="false"
			      key2StringMapper="org.infinispan.loaders.keymappers.DefaultTwoWayKey2StringMapper">
		<dataSource jndiUrl="java:jboss/datasources/JdbcDS"/>
		<string-keyed-table dropOnExit="true"
				  createOnStart="true" 
				  prefix="ISPN_STRING_TABLE">
			<id-column name="ID_COLUMN" 
				  type="VARCHAR(255)" />
			<data-column name="DATA_COLUMN" 
				    type="BINARY" />
			<timestamp-column name="TIMESTAMP_COLUMN" 
					 type="BIGINT" />
		</string-keyed-table>
	</string-keyed-jdbc-store>
</persistence>
Copy to Clipboard Toggle word wrap
For details about the elements and parameters used in this sample configuration, see Section 19.2, “Cache Store Configuration Details (Library Mode)”.
The following is a configuration for the JdbcStringBasedStore in Red Hat JBoss Data Grid's Remote Client-Server mode. This configuration is used when multiple nodes must be used.
<subsystem xmlns="urn:infinispan:server:core:8.3" default-cache-container="default">
	<cache-container <!-- Additional configuration information here --> >
		<!-- Additional configuration elements here -->
      <replicated-cache>
			<!-- Additional configuration elements here -->
	      <string-keyed-jdbc-store datasource="java:jboss/datasources/JdbcDS"
	            		       fetch-state="true"                        
	            		       passivation="false"
	            		       preload="false" 
	            		       purge="false" 
	            		       shared="false" 
	            		       singleton="true"> 
	         <string-keyed-table prefix="JDG">
	             <id-column name="id" 
	                        type="${id.column.type}"/>
	             <data-column name="datum" 
	                          type="${data.column.type}"/>
	             <timestamp-column name="version"
	                               type="${timestamp.column.type}"/>
				</string-keyed-table> 
			</string-keyed-jdbc-store>
		</replicated-cache>
	</cache-container>
</subsystem>
Copy to Clipboard Toggle word wrap
For details about the elements and parameters used in this sample configuration, see Section 19.3, “Cache Store Configuration Details (Remote Client-Server Mode)”.

19.6.3. JdbcMixedStores

The JdbcMixedStore is a hybrid implementation that delegates keys based on their type to either the JdbcBinaryStore or JdbcStringBasedStore.
The following is a configuration for a JdbcMixedStore for Red Hat JBoss Data Grid's Remote Client-Server mode:
<local-cache name="customCache">
	<mixed-keyed-jdbc-store datasource="java:jboss/datasources/JdbcDS" 
				passivation="true" 
				preload="false" 
				purge="false">
		<binary-keyed-table prefix="MIX_BKT2">
			<id-column name="id" 
				   type="${id.column.type}"/>
			<data-column name="datum" 
				     type="${data.column.type}"/>
			<timestamp-column name="version" 
				   	  type="${timestamp.column.type}"/>
		</binary-keyed-table>
		<string-keyed-table prefix="MIX_STR2">
			<id-column name="id" 
				   type="${id.column.type}"/>
			<data-column name="datum" 
				     type="${data.column.type}"/>
			<timestamp-column name="version" 
				   	  type="${timestamp.column.type}"/>
		</string-keyed-table>
	</mixed-keyed-jdbc-store>
</local-cache>
Copy to Clipboard Toggle word wrap
For details about the elements and parameters used in this sample configuration, see Section 19.3, “Cache Store Configuration Details (Remote Client-Server Mode)”.
The following is a sample configuration for the JdbcMixedStore:
<infinispan
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:infinispan:config:8.3 http://www.infinispan.org/schemas/infinispan-config-8.3.xsd
            urn:infinispan:config:store:jdbc:8.0 http://www.infinispan.org/schemas/infinispan-cachestore-jdbc-config-8.0.xsd"
        xmlns="urn:infinispan:config:8.3">
        <!-- Additional configuration elements here -->
	<persistence>
	<mixed-keyed-jdbc-store xmlns="urn:infinispan:config:store:jdbc:8.0"
	                      fetch-state="false"
			      purge="false"
			      key-to-string-mapper="org.infinispan.persistence.keymappers.DefaultTwoWayKey2StringMapper">
		<connection-pool connection-url="jdbc:h2:mem:infinispan_binary_based;DB_CLOSE_DELAY=-1" 
				username="sa" 
				driver="org.h2.Driver"/>
		<binary-keyed-table dropOnExit="true" 
				  createOnStart="true" 
				  prefix="ISPN_BUCKET_TABLE_BINARY">
			<id-column name="ID_COLUMN" 
				  type="VARCHAR(255)" />
			<data-column name="DATA_COLUMN" 
				    type="BINARY" />
			<timestamp-column name="TIMESTAMP_COLUMN" 
					 type="BIGINT" />
		</binary-keyed-table>
		<string-keyed-table dropOnExit="true" 
				  createOnStart="true" 
				  prefix="ISPN_BUCKET_TABLE_STRING">
			<id-column name="ID_COLUMN" 
				  type="VARCHAR(255)" />
			<data-column name="DATA_COLUMN" 
				    type="BINARY" />
			<timestamp-column name="TIMESTAMP_COLUMN" 
					 type="BIGINT" />
		</string-keyed-table>
	</mixed-keyed-jdbc-store>
</persistence>
Copy to Clipboard Toggle word wrap
For details about the elements and parameters used in this sample configuration, see Section 19.2, “Cache Store Configuration Details (Library Mode)”.

19.6.4. Cache Store Troubleshooting

19.6.4.1. IOExceptions with JdbcStringBasedStore

An IOException Unsupported protocol version 48 error when using JdbcStringBasedStore indicates that your data column type is set to VARCHAR, CLOB or something similar instead of the correct type, BLOB or VARBINARY. Despite its name, JdbcStringBasedStore only requires that the keys are strings while the values can be any data type, so that they can be stored in a binary column.
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat