title: Insert json into postgreSQL
body: <p>I'm trying to insert a json object , supplied by the ARC client (similar to postman) into my webService controller, then into a PostgreSQL 11.4 dB, using Java 8, Eclipse and SpringBoot. I'm getting the following error:</p>
  
  <pre><code>2019-07-10 13:02:42.356 ERROR 21516 --- [nio-8086-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.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO cwb_patent(patent_number,created_date,patent_data) VALUES (?,current_timestamp,cast(? AS JSON)) ON CONFLICT (patent_number) DO UPDATE SET patent_data  = cast(? AS JSON), created_date = current_timestamp]; nested exception is org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of com.clarivate.singularity.chemworkbench.webservices.common.PatentChemicalData. Use setObject() with an explicit Types value to specify the type to use.] with root cause
  org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of com.clarivate.singularity.chemworkbench.webservices.common.PatentChemicalData. Use setObject() with an explicit Types value to specify the type to use.
  at org.postgresql.jdbc.PgPreparedStatement.setObject(PgPreparedStatement.java:967) ~[postgresql-42.2.2.jar:42.2.2]
  </code></pre>
  
  <p>My query is:</p>
  
  <pre><code>public static final String mergeCwbPatent = "INSERT INTO cwb_patent" + 
          "(patent_number,created_date,patent_data)" +
          " VALUES (:patent_number,current_timestamp,cast(:patent_data AS JSON))" +
          " ON CONFLICT (patent_number)" +
          " DO UPDATE SET patent_data  = cast(:patent_data AS JSON), created_date = current_timestamp";
  </code></pre>
  
  <p>My controller is:</p>
  
  <pre><code> @RequestMapping(value = "/merge-patent-data", method = RequestMethod.POST)
  public Long  mergePatentChemicalData(@RequestBody  PatentChemicalData patentChemicalData) { 
      Long ret = db.mergeCwbPatent(patentChemicalData);
      return ret;
  }
  </code></pre>
  
  <p>And the method doing the insert is:</p>
  
  <pre><code>public Long mergeCwbPatent(PatentChemicalData pcd)
  {
      Map&lt;String, Object&gt; parameters = new HashMap&lt;String, Object&gt;();
  
      Long ret = null;
      String patentNumber;
  
      if (pcd == null )
      {
          logger.error("DS4A Trying to Insert invalid PatentChemicalData into CWB_PATENT");
      }else {
          patentNumber=pcd.getPatentChemicalData().getPatentNumber();
  
          logger.debug("DS4B Inserting data for patentNumber = " + patentNumber + " into cwb_patent");
          parameters.put("patent_number", patentNumber);  // THIS LINE THROWS THE ERROR
          parameters.put("patent_data", pcd);   // This is the JSON object
  
          ret = jdbcTemplate.queryForObject(SqlQueries.mergeCwbPatent, parameters,Long.class);
  
      }
  
      return ret;
  }
  </code></pre>
  
  <p>The stacktrace says "Use Use setObject()" but that not applicable to my parameters HashMap. 
  This <a href="https://tenmilesquare.com/working-with-spring-jdbc-template-and-postgres-json/" rel="nofollow noreferrer">tenmilessquare</a> link suggests i'm on the right track but I can't seem to get it to work. Any help appreciated.</p>