From e0ea066d3fdf99bcef9b1cdc1c26869eb2863d4e Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 24 Jan 2024 14:35:35 +0100 Subject: [PATCH] HHH-17674 Add test for issue --- .../orm/test/eviction/EvictAndGetTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/eviction/EvictAndGetTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/eviction/EvictAndGetTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/eviction/EvictAndGetTest.java new file mode 100644 index 0000000000..febefbc95e --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/eviction/EvictAndGetTest.java @@ -0,0 +1,50 @@ +package org.hibernate.orm.test.eviction; + +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.Id; + +@DomainModel( + annotatedClasses = EvictAndGetTest.TestEntity.class +) +@SessionFactory +public class EvictAndGetTest { + + @Test + public void testGetAfterEviction(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + TestEntity proxy = session.getReference( TestEntity.class, 1L ); + + TestEntity entity = new TestEntity( 1L ); + session.persist( entity ); + + session.flush(); + + session.evict( entity ); + + session.get( TestEntity.class, 1L ); + } + ); + } + + @Entity(name = "TestEntity") + public static class TestEntity { + + @Id + private Long id; + + private String name; + + public TestEntity() { + } + + public TestEntity(Long id) { + this.id = id; + } + } +}