HHH-16479 Add test for issue
This commit is contained in:
parent
88f1e156a3
commit
31c5be55ed
|
@ -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<T> {
|
||||
|
||||
@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<TestEnum> {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
protected TestEntity() {
|
||||
}
|
||||
|
||||
public TestEntity(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Entity
|
||||
public static class AnotherTestEntity extends GenericBaseEntity<AnotherTestEnum> {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
protected AnotherTestEntity() {
|
||||
}
|
||||
|
||||
public AnotherTestEntity(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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<T extends TestEnum> {
|
||||
|
||||
@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<TestEnum> {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
protected TestEntity() {
|
||||
}
|
||||
|
||||
public TestEntity(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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<T extends EnumBase> {
|
||||
|
||||
@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<TestEnum> {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
protected TestEntity() {
|
||||
}
|
||||
|
||||
public TestEntity(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Entity
|
||||
public static class AnotherTestEntity extends GenericBaseEntity<AnotherTestEnum> {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
protected AnotherTestEntity() {
|
||||
}
|
||||
|
||||
public AnotherTestEntity(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue