Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
Inyectando el parámetro JSON en nativeQuery

Esto funciona cuando

 @Query( value = "SELECT * FROM person WHERE school = :schoolId AND details @> '{\"id\":\"1234\",\"name\":\"John\"}'", nativeQuery = true )

Estoy pasando @Param("schoolId") String schoolId

Pero cuando paso el JSON como parámetro, falla con

 org.springframework.dao.InvalidDataAccessResourceUsageException, could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet org.postgresql.util.PSQLException: ERROR: operator does not exist: jsonb @> character varying Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. @Query(value = "SELECT * FROM person WHERE school = :schoolId AND details @> :details", nativeQuery = true) @Param("schoolId") String schoolId, @Param("details") String details
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Spring+JDBC vincula cadenas como VARCHAR de forma predeterminada. La solución barata aquí es usar cast(s):

 details @> CAST(:details AS jsonb)

Pero, si tiene muchas consultas, en las que algunos tipos no estándar se usan como parámetros y desea vincular su representación de cadena, puede usar el

 stringtype=unspecified

Parámetro JDBC DSN en su cadena de conexión. De esa manera, cada parámetro, que está vinculado por setString() , tendrá un tipo unknown en PostgreSQL, por lo que intentará inferir sus tipos reales.

about 4 years ago · Santiago Trujillo Report

0

Gracias por esto.

Además de la solución, también puedes hacer el reparto como:

details @> :details::jsonb

Estoy usando la versión 11 de postgres, no estoy seguro de cuándo se introdujo.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!