diff --git a/orm/hibernate-orm-6/src/test/java/org/hibernate/entities/EntityArray.java b/orm/hibernate-orm-6/src/test/java/org/hibernate/entities/EntityArray.java new file mode 100644 index 00000000..d9e36b46 --- /dev/null +++ b/orm/hibernate-orm-6/src/test/java/org/hibernate/entities/EntityArray.java @@ -0,0 +1,47 @@ +package org.hibernate.entities; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.type.SqlTypes; + +import java.util.List; + +@Entity +public class EntityArray { + + @Id + @GeneratedValue + private long id; + + @JdbcTypeCode(SqlTypes.ARRAY) + private List listString; + + @JdbcTypeCode(SqlTypes.ARRAY) + private List listInteger; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public List getListString() { + return listString; + } + + public void setListString(List listA) { + this.listString = listA; + } + + public List getListInteger() { + return listInteger; + } + + public void setListInteger(List listB) { + this.listInteger = listB; + } +} diff --git a/orm/hibernate-orm-6/src/test/java/org/hibernate/entities/EntityJSON.java b/orm/hibernate-orm-6/src/test/java/org/hibernate/entities/EntityJSON.java new file mode 100644 index 00000000..1e6a6027 --- /dev/null +++ b/orm/hibernate-orm-6/src/test/java/org/hibernate/entities/EntityJSON.java @@ -0,0 +1,47 @@ +package org.hibernate.entities; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.type.SqlTypes; + +import java.util.List; + +@Entity +public class EntityJSON { + + @Id + @GeneratedValue + private long id; + + @JdbcTypeCode(SqlTypes.JSON) + private List listString; + + @JdbcTypeCode(SqlTypes.JSON) + private List listInteger; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public List getListString() { + return listString; + } + + public void setListString(List listA) { + this.listString = listA; + } + + public List getListInteger() { + return listInteger; + } + + public void setListInteger(List listB) { + this.listInteger = listB; + } +} diff --git a/orm/hibernate-orm-6/src/test/java/org/hibernate/entities/EntityPlain.java b/orm/hibernate-orm-6/src/test/java/org/hibernate/entities/EntityPlain.java new file mode 100644 index 00000000..9c7c919b --- /dev/null +++ b/orm/hibernate-orm-6/src/test/java/org/hibernate/entities/EntityPlain.java @@ -0,0 +1,45 @@ +package org.hibernate.entities; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.type.SqlTypes; + +import java.util.List; + +@Entity +public class EntityPlain { + + @Id + @GeneratedValue + private long id; + + private List listString; + + private List listInteger; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public List getListString() { + return listString; + } + + public void setListString(List listA) { + this.listString = listA; + } + + public List getListInteger() { + return listInteger; + } + + public void setListInteger(List listB) { + this.listInteger = listB; + } +} diff --git a/orm/hibernate-orm-6/src/test/java/org/hibernate/test/EntityArrayLoadedFirstTestCase.java b/orm/hibernate-orm-6/src/test/java/org/hibernate/test/EntityArrayLoadedFirstTestCase.java new file mode 100644 index 00000000..4949fff3 --- /dev/null +++ b/orm/hibernate-orm-6/src/test/java/org/hibernate/test/EntityArrayLoadedFirstTestCase.java @@ -0,0 +1,79 @@ +package org.hibernate.test; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.entities.EntityArray; +import org.hibernate.entities.EntityJSON; +import org.hibernate.entities.EntityPlain; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.type.Type; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * This template demonstrates how to develop a standalone test case for Hibernate ORM. Although this is perfectly + * acceptable as a reproducer, usage of ORMUnitTestCase is preferred! + */ +public class EntityArrayLoadedFirstTestCase { + + private Metadata metadata; + private SessionFactory sf; + + @Before + public void setup() { + StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder() + // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. + .applySetting( "hibernate.show_sql", "true" ) + .applySetting( "hibernate.format_sql", "true" ) + .applySetting( "hibernate.hbm2ddl.auto", "update" ); + + metadata = new MetadataSources( srb.build() ) + // Add your entities here. + .addAnnotatedClass( EntityArray.class ) + .addAnnotatedClass( EntityJSON.class ) + .addAnnotatedClass( EntityPlain.class ) + .buildMetadata(); + + sf = metadata.buildSessionFactory(); + } + + // Add your tests, using standard JUnit. + @Test + public void hhh17680Test() throws Exception { + var modelEntityArray = metadata.getEntityBinding(EntityArray.class.getName()); + var modelEntityJson = metadata.getEntityBinding(EntityJSON.class.getName()); + var modelEntityPlain = metadata.getEntityBinding(EntityPlain.class.getName()); + + // Entities with JdbcTypes JSON and ARRAY should have different types + Assert.assertNotEquals( + "Entity with JdbcType ARRAY and entity with JdbcType JSON should have the different types", + getPropertyType(modelEntityArray, "listString"), + getPropertyType(modelEntityJson, "listString") + ); + Assert.assertNotEquals( + "Entity with JdbcType ARRAY and entity with JdbcType JSON should have the different types", + getPropertyType(modelEntityArray, "listInteger"), + getPropertyType(modelEntityJson, "listInteger") + ); + + // + Assert.assertEquals( + "Entity with JdbcType ARRAY and entity without JdbcType should have the same types", + getPropertyType(modelEntityArray, "listString"), + getPropertyType(modelEntityPlain, "listString") + ); + Assert.assertEquals( + "Entity with JdbcType ARRAY and entity without JdbcType should have the same types", + getPropertyType(modelEntityArray, "listInteger"), + getPropertyType(modelEntityPlain, "listInteger") + ); + } + + private Type getPropertyType(PersistentClass model, String property) { + return model.getProperty(property).getType(); + } + +} diff --git a/orm/hibernate-orm-6/src/test/java/org/hibernate/test/EntityJsonLoadedFirstTestCase.java b/orm/hibernate-orm-6/src/test/java/org/hibernate/test/EntityJsonLoadedFirstTestCase.java new file mode 100644 index 00000000..4a6c865a --- /dev/null +++ b/orm/hibernate-orm-6/src/test/java/org/hibernate/test/EntityJsonLoadedFirstTestCase.java @@ -0,0 +1,78 @@ +package org.hibernate.test; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.entities.EntityArray; +import org.hibernate.entities.EntityJSON; +import org.hibernate.entities.EntityPlain; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.type.Type; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * This template demonstrates how to develop a standalone test case for Hibernate ORM. Although this is perfectly + * acceptable as a reproducer, usage of ORMUnitTestCase is preferred! + */ +public class EntityJsonLoadedFirstTestCase { + + private Metadata metadata; + private SessionFactory sf; + + @Before + public void setup() { + StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder() + // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. + .applySetting( "hibernate.show_sql", "true" ) + .applySetting( "hibernate.format_sql", "true" ) + .applySetting( "hibernate.hbm2ddl.auto", "update" ); + + metadata = new MetadataSources( srb.build() ) + // Add your entities here. + .addAnnotatedClass( EntityJSON.class ) + .addAnnotatedClass( EntityArray.class ) + .addAnnotatedClass( EntityPlain.class ) + .buildMetadata(); + + sf = metadata.buildSessionFactory(); + } + + // Add your tests, using standard JUnit. + @Test + public void hhh17680Test() throws Exception { + var modelEntityArray = metadata.getEntityBinding(EntityArray.class.getName()); + var modelEntityJson = metadata.getEntityBinding(EntityJSON.class.getName()); + var modelEntityPlain = metadata.getEntityBinding(EntityPlain.class.getName()); + + // Entities with JdbcTypes JSON and ARRAY should have different types + Assert.assertNotEquals( + "Entity with JdbcType ARRAY and entity with JdbcType JSON should have the different types", + getPropertyType(modelEntityArray, "listString"), + getPropertyType(modelEntityJson, "listString") + ); + Assert.assertNotEquals( + "Entity with JdbcType ARRAY and entity with JdbcType JSON should have the different types", + getPropertyType(modelEntityArray, "listInteger"), + getPropertyType(modelEntityJson, "listInteger") + ); + + // + Assert.assertEquals( + "Entity with JdbcType ARRAY and entity without JdbcType should have the same types", + getPropertyType(modelEntityArray, "listString"), + getPropertyType(modelEntityPlain, "listString") + ); + Assert.assertEquals( + "Entity with JdbcType ARRAY and entity without JdbcType should have the same types", + getPropertyType(modelEntityArray, "listInteger"), + getPropertyType(modelEntityPlain, "listInteger") + ); + } + + private Type getPropertyType(PersistentClass model, String property) { + return model.getProperty(property).getType(); + } +} diff --git a/orm/hibernate-orm-6/src/test/java/org/hibernate/test/EntityPlainLoadedFirstTestCase.java b/orm/hibernate-orm-6/src/test/java/org/hibernate/test/EntityPlainLoadedFirstTestCase.java new file mode 100644 index 00000000..44c02f54 --- /dev/null +++ b/orm/hibernate-orm-6/src/test/java/org/hibernate/test/EntityPlainLoadedFirstTestCase.java @@ -0,0 +1,79 @@ +package org.hibernate.test; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.entities.EntityArray; +import org.hibernate.entities.EntityJSON; +import org.hibernate.entities.EntityPlain; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.type.Type; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * This template demonstrates how to develop a standalone test case for Hibernate ORM. Although this is perfectly + * acceptable as a reproducer, usage of ORMUnitTestCase is preferred! + */ +public class EntityPlainLoadedFirstTestCase { + + private Metadata metadata; + private SessionFactory sf; + + @Before + public void setup() { + StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder() + // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults. + .applySetting( "hibernate.show_sql", "true" ) + .applySetting( "hibernate.format_sql", "true" ) + .applySetting( "hibernate.hbm2ddl.auto", "update" ); + + metadata = new MetadataSources( srb.build() ) + // Add your entities here. + .addAnnotatedClass( EntityPlain.class ) + .addAnnotatedClass( EntityJSON.class ) + .addAnnotatedClass( EntityArray.class ) + .buildMetadata(); + + sf = metadata.buildSessionFactory(); + } + + // Add your tests, using standard JUnit. + @Test + public void hhh17680Test() throws Exception { + var modelEntityArray = metadata.getEntityBinding(EntityArray.class.getName()); + var modelEntityJson = metadata.getEntityBinding(EntityJSON.class.getName()); + var modelEntityPlain = metadata.getEntityBinding(EntityPlain.class.getName()); + + // Entities with JdbcTypes JSON and ARRAY should have different types + Assert.assertNotEquals( + "Entity with JdbcType ARRAY and entity with JdbcType JSON should have the different types", + getPropertyType(modelEntityArray, "listString"), + getPropertyType(modelEntityJson, "listString") + ); + Assert.assertNotEquals( + "Entity with JdbcType ARRAY and entity with JdbcType JSON should have the different types", + getPropertyType(modelEntityArray, "listInteger"), + getPropertyType(modelEntityJson, "listInteger") + ); + + // + Assert.assertEquals( + "Entity with JdbcType ARRAY and entity without JdbcType should have the same types", + getPropertyType(modelEntityArray, "listString"), + getPropertyType(modelEntityPlain, "listString") + ); + Assert.assertEquals( + "Entity with JdbcType ARRAY and entity without JdbcType should have the same types", + getPropertyType(modelEntityArray, "listInteger"), + getPropertyType(modelEntityPlain, "listInteger") + ); + } + + private Type getPropertyType(PersistentClass model, String property) { + return model.getProperty(property).getType(); + } + +}