Up to the following version of hibernate-core
implementation ‘org.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 ‘org.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.
3
Due to compatibility issues with spatial extensions or configuration changes, inserting Hibernate EntityManager and spatial data might result in issues after upgrading the dependency version. Check that your dialect or configuration settings are updated, and that Hibernate Spatial is included with the correct version.
sudha academy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1