Ronny Bräunlich (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=62f2786...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNmVmZTkxZmJi...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16662?atlOrigin=eyJpIjoiNmVmZT...
) HHH-16662 (
https://hibernate.atlassian.net/browse/HHH-16662?atlOrigin=eyJpIjoiNmVmZT...
) Postgres Mapping of JSON column to Map<> causes class cast exception (
https://hibernate.atlassian.net/browse/HHH-16662?atlOrigin=eyJpIjoiNmVmZT...
)
Issue Type: Bug Affects Versions: 6.2.2 Assignee: Unassigned Components: hibernate-core
Created: 22/May/2023 01:05 AM Environment: PostgreSQL 14.3
PostgreSQL driver version 42.6.0
Hibernate Core 6.2.2.Final
JDK 19 Priority: Major Reporter: Ronny Bräunlich (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=62f2786...
)
Hi everyone,
I execute a native query via Spring Data JPA and dynamically insert them into a projection
interface.
The database column definition is a jsonb column and the interface I select into has a
field:
val properties: Map<String, Any?>
the original entity has the backing field defined like this:
import io.hypersistence.utils.hibernate.type.json.JsonType
...
@Type(JsonType::class)
@Column(columnDefinition = "jsonb")
val properties: Map<String, Any?>
With Hibernate 6.1.7.Final it would work because in the method
buildJdbcTypeCodeToJavaClassMappings in JdbcTypeJavaClassMappings (see
https://github.com/hibernate/hibernate-orm/blob/6.1.7/hibernate-core/src/...
) there was no mapping defined for the JSON type. Therefore, Object.class has been
returned and in the end the Map was passed on as is.
With Hibernate 6.2.x and
https://hibernate.atlassian.net/browse/HHH-15748 the
implementation changed and now JSON is mapped to String.class all times. This causes a
ClassCastException during my persistence tests:
class java.lang.String cannot be cast to class java.util.Map
I wonder why with the Oracle specific task the mapping has been changed in a central
class, since Oracle became its own OracleTypes class.
(
https://hibernate.atlassian.net/browse/HHH-16662#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16662#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:bbd69a1 )