diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/EnumeratedAndGenerics2Test.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/EnumeratedAndGenerics2Test.java new file mode 100644 index 0000000000..ff6843b9b9 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/EnumeratedAndGenerics2Test.java @@ -0,0 +1,110 @@ +package org.hibernate.orm.test.annotations.enumerated; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@DomainModel( + annotatedClasses = { + EnumeratedAndGenerics2Test.TestEntity.class, + EnumeratedAndGenerics2Test.AnotherTestEntity.class, + } +) +@SessionFactory +@TestForIssue(jiraKey = "HHH-16479") +public class EnumeratedAndGenerics2Test { + + @Test + public void setUp(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + TestEntity entity = new TestEntity( 1l ); + entity.setState( TestEnum.BAR ); + session.persist( entity ); + + AnotherTestEntity anotherTest = new AnotherTestEntity( 2l ); + anotherTest.setState( AnotherTestEnum.TWO ); + session.persist( anotherTest ); + } + ); + + scope.inTransaction( + session -> { + TestEntity entity = session.get( TestEntity.class, 1l ); + assertThat( entity ).isNotNull(); + assertThat( entity.getState() ).isEqualTo( TestEnum.BAR ); + + AnotherTestEntity anotherTest = session.get( AnotherTestEntity.class, 2L ); + assertThat( anotherTest ).isNotNull(); + assertThat( anotherTest.getState() ).isEqualTo( AnotherTestEnum.TWO ); + } + ); + } + + public interface EnumBase { + String name(); + } + + public enum TestEnum implements EnumBase { + FOO, BAR + } + + public enum AnotherTestEnum implements EnumBase { + ONE, TWO + } + + @MappedSuperclass + public static abstract class GenericBaseEntity { + + @Enumerated(EnumType.STRING) + protected T state; + + public T getState() { + return state; + } + + public void setState(T state) { + this.state = state; + } + } + + @Entity + public static class TestEntity extends GenericBaseEntity { + + @Id + private long id; + + protected TestEntity() { + } + + public TestEntity(long id) { + this.id = id; + } + + } + + @Entity + public static class AnotherTestEntity extends GenericBaseEntity { + + @Id + private long id; + + protected AnotherTestEntity() { + } + + public AnotherTestEntity(long id) { + this.id = id; + } + + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/EnumeratedAndGenerics3Test.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/EnumeratedAndGenerics3Test.java new file mode 100644 index 0000000000..e97a99920a --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/EnumeratedAndGenerics3Test.java @@ -0,0 +1,85 @@ +package org.hibernate.orm.test.annotations.enumerated; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@DomainModel( + annotatedClasses = { + EnumeratedAndGenerics3Test.TestEntity.class, + } +) +@SessionFactory +@TestForIssue(jiraKey = "HHH-16479") +public class EnumeratedAndGenerics3Test { + + @Test + public void setUp(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + TestEntity entity = new TestEntity( 1l ); + entity.setState( TestEnum.BAR ); + session.persist( entity ); + + } + ); + + scope.inTransaction( + session -> { + TestEntity entity = session.get( TestEntity.class, 1l ); + assertThat( entity ).isNotNull(); + assertThat( entity.getState() ).isEqualTo( TestEnum.BAR ); + + } + ); + } + + public interface EnumBase { + String name(); + } + + public enum TestEnum implements EnumBase { + FOO, BAR + } + + @MappedSuperclass + public static abstract class GenericBaseEntity { + + @Enumerated(EnumType.STRING) + protected T state; + + public T getState() { + return state; + } + + public void setState(T state) { + this.state = state; + } + } + + @Entity + public static class TestEntity extends GenericBaseEntity { + + @Id + private long id; + + protected TestEntity() { + } + + public TestEntity(long id) { + this.id = id; + } + + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/EnumeratedAndGenericsTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/EnumeratedAndGenericsTest.java new file mode 100644 index 0000000000..77352afd7e --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/EnumeratedAndGenericsTest.java @@ -0,0 +1,110 @@ +package org.hibernate.orm.test.annotations.enumerated; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@DomainModel( + annotatedClasses = { + EnumeratedAndGenericsTest.TestEntity.class, + EnumeratedAndGenericsTest.AnotherTestEntity.class, + } +) +@SessionFactory +@TestForIssue( jiraKey = "HHH-16479") +public class EnumeratedAndGenericsTest { + + @Test + public void setUp(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + TestEntity entity = new TestEntity( 1l ); + entity.setState( TestEnum.BAR ); + session.persist( entity ); + + AnotherTestEntity anotherTest = new AnotherTestEntity( 2l ); + anotherTest.setState( AnotherTestEnum.TWO ); + session.persist( anotherTest ); + } + ); + + scope.inTransaction( + session -> { + TestEntity entity = session.get( TestEntity.class, 1l ); + assertThat( entity ).isNotNull(); + assertThat( entity.getState() ).isEqualTo( TestEnum.BAR ); + + AnotherTestEntity anotherTest = session.get( AnotherTestEntity.class, 2L ); + assertThat( anotherTest ).isNotNull(); + assertThat( anotherTest.getState() ).isEqualTo( AnotherTestEnum.TWO ); + } + ); + } + + public interface EnumBase { + String name(); + } + + public enum TestEnum implements EnumBase { + FOO, BAR + } + + public enum AnotherTestEnum implements EnumBase { + ONE, TWO + } + + @MappedSuperclass + public static abstract class GenericBaseEntity { + + @Enumerated(EnumType.STRING) + protected T state; + + public T getState() { + return state; + } + + public void setState(T state) { + this.state = state; + } + } + + @Entity + public static class TestEntity extends GenericBaseEntity { + + @Id + private long id; + + protected TestEntity() { + } + + public TestEntity(long id) { + this.id = id; + } + + } + + @Entity + public static class AnotherTestEntity extends GenericBaseEntity { + + @Id + private long id; + + protected AnotherTestEntity() { + } + + public AnotherTestEntity(long id) { + this.id = id; + } + + } +}