Alex Nistico (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzdhMDUxNWQz...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16490?atlOrigin=eyJpIjoiNzdhMD...
) HHH-16490 (
https://hibernate.atlassian.net/browse/HHH-16490?atlOrigin=eyJpIjoiNzdhMD...
) The discriminator type mapper overrides any custom type specfied for a field mapped over
the same column (
https://hibernate.atlassian.net/browse/HHH-16490?atlOrigin=eyJpIjoiNzdhMD...
)
Issue Type: Bug Affects Versions: 6.1.7, 6.2.1 Assignee: Unassigned Components:
hibernate-core Created: 18/Apr/2023 18:08 PM Environment: Hibernate 6.1.7 and 6.2.1
Java 17
Postgres 13
Priority: Major Reporter: Alex Nistico (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
If an entity maps a field and the discriminator on the same column, the entity persister
tries to use the same value persister for both the discriminator and the field, which
causes problems if the field is mapped using a different type.
A simplified example of the situation is:
@Entity
@Inheritance(strategy = SINGLE_TABLE)
@DiscriminatorColumn(name = "code")
public abstract class MarketValue {
@Id
@GeneratedValue(strategy = AUTO)
private final Long id;
@Column(nullable = false, insertable = false, updatable = false)
private final MarketId code;
....
}
Where MarketId has a JavaType registered in the type contributions.
If I try do read an instance from the database I get the following exception:
Caused by: java.lang.IllegalArgumentException: Can not set final
com.example.demo.model.MarketId field com.example.demo.model.MarketValue.code to
java.lang.String
at
java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
~[na:na]
at
java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
~[na:na]
at
java.base/jdk.internal.reflect.UnsafeQualifiedObjectFieldAccessorImpl.set(UnsafeQualifiedObjectFieldAccessorImpl.java:83)
~[na:na]
at java.base/java.lang.reflect.Field.set(Field.java:799) ~[na:na]
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:53)
~[hibernate-core-6.1.7.Final.jar:6.1.7.Final]
... 103 common frames omitted
(
https://hibernate.atlassian.net/browse/HHH-16490#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16490#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#100222- sha1:c08beee )