HHH-10162 - Add test
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
parent
9da230a616
commit
9c4baed5ae
50
hibernate-core/src/test/java/org/hibernate/orm/test/cache/polymorphism/CacheHolder.java
vendored
Normal file
50
hibernate-core/src/test/java/org/hibernate/orm/test/cache/polymorphism/CacheHolder.java
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.cache.polymorphism;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian Beikov
|
||||
*/
|
||||
@Entity
|
||||
public class CacheHolder {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@ManyToOne(optional = false, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private Cacheable item;
|
||||
|
||||
public CacheHolder() {
|
||||
}
|
||||
|
||||
public CacheHolder(String id, Cacheable item) {
|
||||
this.id = id;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Cacheable getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(Cacheable item) {
|
||||
this.item = item;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ package org.hibernate.orm.test.cache.polymorphism;
|
|||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.annotations.ConcreteProxy;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
@ -18,6 +19,7 @@ import jakarta.persistence.Id;
|
|||
*/
|
||||
@Entity
|
||||
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
@ConcreteProxy
|
||||
public class Cacheable {
|
||||
private Long id;
|
||||
private String name;
|
||||
|
|
|
@ -26,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*/
|
||||
@JiraKey( "HHH-9028" )
|
||||
@JiraKey( "HHH-9107" )
|
||||
@DomainModel( annotatedClasses = { Cacheable.class, CachedItem1.class, CachedItem2.class } )
|
||||
@DomainModel( annotatedClasses = { Cacheable.class, CachedItem1.class, CachedItem2.class, CacheHolder.class } )
|
||||
@SessionFactory
|
||||
public class PolymorphicCacheTest {
|
||||
@BeforeEach
|
||||
|
@ -39,7 +39,12 @@ public class PolymorphicCacheTest {
|
|||
|
||||
@AfterEach
|
||||
public void dropTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (session) -> session.createQuery( "delete Cacheable" ).executeUpdate() );
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createMutationQuery("delete from CacheHolder").executeUpdate();
|
||||
session.createMutationQuery( "delete Cacheable" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -140,4 +145,27 @@ public class PolymorphicCacheTest {
|
|||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@JiraKey("HHH-10162")
|
||||
public void testPolymorphismAndCacheWithHolder(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
final CachedItem1 item3 = new CachedItem1(3, "name3");
|
||||
final CacheHolder holder = new CacheHolder( "holder", item3 );
|
||||
s.persist( item3 );
|
||||
s.persist( holder );
|
||||
}
|
||||
);
|
||||
|
||||
scope.inTransaction(
|
||||
s -> {
|
||||
CacheHolder cacheHolder = s.get( CacheHolder.class, "holder" );
|
||||
Assertions.assertTrue(
|
||||
cacheHolder.getItem() instanceof CachedItem1,
|
||||
"Relation was not fetched from L2 cache"
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue