Up to the following version of hibernate-core
implementation '.hibernate.orm:hibernate-core:6.6.0.Alpha1'
it would be possible to perform the following code successfully:
INSERT INTO example_table (geom)
VALUES (
ST_SetSRID(
ST_GeomFromGeoJSON(
$dollar${"type":"Point","coordinates":[-34.4214,-15.9216]}$dollar$
),
4326
)
)
ON CONFLICT DO NOTHING;
Which hibernate would run the following statement:
INSERT INTO example_table (geom)
VALUES (
ST_SetSRID(
ST_GeomFromGeoJSON(
$dollar${"type":"Point","coordinates":[-34.4214,-15.9216]}$dollar$
),
4326
)
)
ON CONFLICT DO NOTHING;;
But after upgrading that dependency to:
implementation '.hibernate.orm:hibernate-core:6.6.0.CR1' OR ABOVE, the same query would cause hibernate to try to execute the following statement:
INSERT INTO example_table (geom)
VALUES (
ST_SetSRID(
ST_GeomFromGeoJSON(
$dollar$""""""{type:Point,coordinates:[-34.4214,-15.9216]}$dollar$
),
4326
)
)
ON CONFLICT DO NOTHING;;
Which leads to the following exception: [ERROR: unknown GeoJSON type] [n/a].
Those queries are run using EntityManager.createNativeQuery(query).
Does anyone know why this started happening (multiple double quotes in the query)? I couldn't find anything about it in the release notes. The only way I found to solve this issue was taking off the dollar quote and surrounding the json with single quotes, which is not what I want to do.
This happens to every version above 6.6.0.CR1, including the one used by spring data jpa from spring boot 3.4.x.
edit. 1
I need to use native queries for batch inserts with upsert behavior. Hibernate/JPA does not support operations like ON CONFLICT DO NOTHING.
edit. 2
This issue seems to happen with JSON data in general, not just with GeoJson type.