[JIRA] (HHH-15929) Mapping jsonb of different types in a class inheritance hierarchy does not work.
by Gavin King (JIRA)
Gavin King ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HHH-15929 ( https://hibernate.atlassian.net/browse/HHH-15929?atlOrigin=eyJpIjoiYWExNT... )
Re: Mapping jsonb of different types in a class inheritance hierarchy does not work. ( https://hibernate.atlassian.net/browse/HHH-15929?atlOrigin=eyJpIjoiYWExNT... )
FTR, here is my test code:
In import.sql :
INSERT INTO table_test(id, type, property) VALUES('1','A','{"propertyA": "valueA"}'::jsonb)
INSERT INTO table_test(id, type, property) VALUES('2','B','{"propertyB": "valueB"}'::jsonb)
In Main.java :
public class Main {
public static void main( String [] args) {
var sessionFactory = new Configuration()
.addAnnotatedClass(CommonEntity.class)
.addAnnotatedClass(EntityA.class)
.addAnnotatedClass(EntityB.class)
// use Postgres
.setProperty(URL, "jdbc:postgresql: //localhost/hreact" )
.setProperty(USER, "hreact" )
.setProperty(PASS, "hreact" )
// display SQL in console
.setProperty(SHOW_SQL, TRUE.toString())
.setProperty(FORMAT_SQL, TRUE.toString())
.setProperty(HIGHLIGHT_SQL, TRUE.toString())
.buildSessionFactory();
// export the inferred database schema
sessionFactory.getSchemaManager().dropMappedObjects( false );
sessionFactory.getSchemaManager().exportMappedObjects( true );
sessionFactory.inSession(session -> {
var ea = session.find(EntityA. class, 1);
var eb = session.find(EntityB. class, 2);
});
}
}
Executed SQL:
[Hibernate]
drop table if exists table_test cascade
[Hibernate]
create table table_test (
type varchar (31) not null ,
id bigint not null ,
property jsonb,
primary key (id)
)
[INFO] HHH000476: Executing script ' file :/Users/gavin/Downloads/test/untitled/build/resources/main/import. sql '
[Hibernate] INSERT INTO table_test(id, type , property) VALUES ( '1' , ' A ' , '{ "propertyA" : "valueA" }' ::jsonb)
[Hibernate] INSERT INTO table_test(id, type , property) VALUES ( '2' , 'B' , '{ "propertyB" : "valueB" }' ::jsonb)
[Hibernate]
select
e1_0.id,
e1_0.property
from
table_test e1_0
where
e1_0. type = ' A '
and e1_0.id=?
[Hibernate]
select
e1_0.id,
e1_0.property
from
table_test e1_0
where
e1_0. type = 'B'
and e1_0.id=?
( https://hibernate.atlassian.net/browse/HHH-15929#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15929#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#100225- sha1:e4eb869 )
2 years, 11 months