Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-17680 Reproducer #400

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<String> listString;

@JdbcTypeCode(SqlTypes.ARRAY)
private List<Integer> listInteger;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public List<String> getListString() {
return listString;
}

public void setListString(List<String> listA) {
this.listString = listA;
}

public List<Integer> getListInteger() {
return listInteger;
}

public void setListInteger(List<Integer> listB) {
this.listInteger = listB;
}
}
Original file line number Diff line number Diff line change
@@ -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<String> listString;

@JdbcTypeCode(SqlTypes.JSON)
private List<Integer> listInteger;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public List<String> getListString() {
return listString;
}

public void setListString(List<String> listA) {
this.listString = listA;
}

public List<Integer> getListInteger() {
return listInteger;
}

public void setListInteger(List<Integer> listB) {
this.listInteger = listB;
}
}
Original file line number Diff line number Diff line change
@@ -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<String> listString;

private List<Integer> listInteger;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public List<String> getListString() {
return listString;
}

public void setListString(List<String> listA) {
this.listString = listA;
}

public List<Integer> getListInteger() {
return listInteger;
}

public void setListInteger(List<Integer> listB) {
this.listInteger = listB;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}

}