title: Spring Data Jdbc and Oracle21c
body: <p>for my latest assignment I'm developing a Spring boot application which will connect with an Oracle 21c database.</p>
  <p>The feature of the oracle release we're interested in is the native JSON data type called OSON (reference here: <a href="https://docs.oracle.com/en/database/oracle/oracle-database/21/adjsn/json-in-oracle-database.html#GUID-F6282E67-CBDF-442E-946F-5F781BC14F33" rel="nofollow noreferrer">Oracle 21c JSON data type</a> )</p>
  <p>I've developed an old fashion DAO approach to accomplish the task, but I would like to use Spring Data JDBC project for the data access layer ideally with minimal extra configuration.</p>
  <p>Actually I'm struggling with the mapping of the columns where the OSON type will be stored. After several tries I've obtained the error below following the idea of creating a custom converter for the datatype.</p>
  <p>Any suggestion on how to proceed?</p>
  <p>pom:</p>
  <pre><code>&lt;!-- ORACLE --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.oracle.database.jdbc&lt;/groupId&gt;
          &lt;artifactId&gt;ojdbc11-production&lt;/artifactId&gt;
          &lt;version&gt;21.1.0.0&lt;/version&gt;
          &lt;type&gt;pom&lt;/type&gt;
      &lt;/dependency&gt;
  &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jdbc&lt;/artifactId&gt;
      &lt;/dependency&gt;
  </code></pre>
  <p>Entity class:</p>
  <pre><code>@Table(&quot;T_BUDGET&quot;)
  @Data @NoArgsConstructor
  public class BudgetEntityData {
  
          @Id
          private Long id;
  
          @Column(&quot;BUDGET&quot;)
          private JsonObjectWrapper budget;
  }
  </code></pre>
  <p>Wrapper used for the converter:</p>
  <pre><code>@Data
  public class JsonObjectWrapper {
  
      private OracleJsonValue json;
  
  }
  </code></pre>
  <p>Jdbc configuration with custom converter:</p>
  <pre><code>@Configuration
  @EnableJdbcRepositories
  public class JdbcConfig extends AbstractJdbcConfiguration {
  
          //utility object used to centralize the use of OracleJsonFactory, not involved in the problem
          private static OracleJsonFactoryWrapper factoryWrapper = new OracleJsonFactoryWrapper(new ObjectMapper()
                  .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
                  .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false),
                   new OracleJsonFactory());
  
          @Override
          public JdbcCustomConversions jdbcCustomConversions() {
              return new JdbcCustomConversions(Arrays.asList(StringToJsonObjectWrapper.INSTANCE,JsonObjectWrapperToString.INSTANCE));
          }
  
          @WritingConverter
          enum JsonObjectWrapperToString implements Converter&lt;JsonObjectWrapper, String&gt; {
  
              INSTANCE;
  
              @Override
              public String convert(JsonObjectWrapper source) {
                  return source.toString();
              }
          }
  
          @ReadingConverter
          enum StringToJsonObjectWrapper implements  Converter&lt;String, JsonObjectWrapper&gt; {
  
              INSTANCE;
  
              @Override
              public JsonObjectWrapper convert(String source) {
                  JsonObjectWrapper jsonObjectWrapper = new JsonObjectWrapper();
                  OracleJsonValue osonObject = factoryWrapper.createOsonObject(source);
                  jsonObjectWrapper.setJson(osonObject);
                  return jsonObjectWrapper;
              }
          }
  }
  </code></pre>
  <p>Error:</p>
  <blockquote>
  <p>2022-04-07 09:47:27.335 DEBUG 24220 --- [nio-8080-exec-1] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query
  2022-04-07 09:47:27.335 DEBUG 24220 --- [nio-8080-exec-1] o.s.jdbc.core.JdbcTemplate               : <strong>Executing prepared SQL statement [SELECT &quot;T_BUDGET&quot;.&quot;ID&quot; AS &quot;ID&quot;, &quot;T_BUDGET&quot;.&quot;BUDGET&quot; AS &quot;BUDGET&quot; FROM &quot;T_BUDGET&quot;]</strong>
  2022-04-07 09:48:58.006 ERROR 24220 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.mapping.MappingException: Could not read value BUDGET from result set!] with root cause</p>
  <p>java.sql.SQLException: <strong>Invalid column type: getOracleObject not
  implemented for class oracle.jdbc.driver.T4CJsonAccessor</strong>    at
  oracle.jdbc.driver.GeneratedAccessor.getOracleObject(GeneratedAccessor.java:1221)
  ~[ojdbc11-21.1.0.0.jar:21.1.0.0.0]    at
  oracle.jdbc.driver.JsonAccessor.getObject(JsonAccessor.java:200)
  ~[ojdbc11-21.1.0.0.jar:21.1.0.0.0]    at
  oracle.jdbc.driver.GeneratedStatement.getObject(GeneratedStatement.java:196)
  ~[ojdbc11-21.1.0.0.jar:21.1.0.0.0]    at
  oracle.jdbc.driver.GeneratedScrollableResultSet.getObject(GeneratedScrollableResultSet.java:334)
  ~[ojdbc11-21.1.0.0.jar:21.1.0.0.0]    at
  com.zaxxer.hikari.pool.HikariProxyResultSet.getObject(HikariProxyResultSet.java)
  ~[HikariCP-3.4.5.jar:na]  at
  org.springframework.jdbc.support.JdbcUtils.getResultSetValue(JdbcUtils.java:283)
  ~[spring-jdbc-5.3.8.jar:5.3.8]</p>
  </blockquote>