[JIRA] (HHH-17026) Object serialization not working with @DiscriminatorColumn and Kotlin
by Marco De Toma (JIRA)
Marco De Toma ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiODc4OWYyMjNm... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-17026?atlOrigin=eyJpIjoiODc4OW... ) HHH-17026 ( https://hibernate.atlassian.net/browse/HHH-17026?atlOrigin=eyJpIjoiODc4OW... ) Object serialization not working with @DiscriminatorColumn and Kotlin ( https://hibernate.atlassian.net/browse/HHH-17026?atlOrigin=eyJpIjoiODc4OW... )
Issue Type: Bug Affects Versions: 6.2.7 Assignee: Unassigned Created: 02/Aug/2023 03:56 AM Priority: Blocker Reporter: Marco De Toma ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
First of all, I apologise in advance if this is the not right place to report this bug.
I encounter this error after upgrading to hibernate 6 but, based on my findings, it occurs only with Kotlin (it works properly in Java).
I decided to open a ticket here because it works properly with Hibernate version 5.x
Context
I have this table
CREATE TABLE vehicles (
id uuid DEFAULT random_uuid(),
vehicle_type varchar (255) not null ,
brand varchar (255) not null
);
insert into vehicles (vehicle_type, brand) values ( 'CAR' , 'Audi' )
and defined two entities with SINGLE_TABLE hierarchy:
@Entity
@Table(name = "vehicles")
@DiscriminatorColumn(name = "vehicle_type", discriminatorType = DiscriminatorType.STRING)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
abstract class VehicleKotlin(
@Id
open var id: UUID,
@Column(name = "brand")
open var brand: String,
)
@Entity
@DiscriminatorValue("CAR")
data class CarKotlin(
@Id override var id: UUID,
override var brand: String,
) : VehicleKotlin(
id = id,
brand = brand,
)
Error
When I try to query the database
FROM VehicleKotlin WHERE brand =’s
it seems like that the serialization does not work work properly.
As you can see in the attachment, id and brand are null while VehicleKotlin.id` and`VehicleKotlin.brand` are set with the right values (but they don’t even exist in the model).
In this demo ( https://github.com/detomarco/hibernate-bug-report ) you can find the same code work properly in Java but not in Koltin.
Thank you in advance
( https://hibernate.atlassian.net/browse/HHH-17026#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-17026#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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100233- sha1:8d17c5d )
10 months, 4 weeks