HHH-18041 Add test for issue

This commit is contained in:
Andrea Boriero 2024-04-30 21:29:43 +02:00 committed by Steve Ebersole
parent ebbb36cf71
commit b894a8d228
4 changed files with 149 additions and 0 deletions

View File

@ -0,0 +1,31 @@
package org.hibernate.orm.test.jpa.cacheable.disableselective;
public class City {
private Long id;
private String name;
public City() {
}
public City(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,51 @@
package org.hibernate.orm.test.jpa.cacheable.disableselective;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Cache;
import jakarta.persistence.SharedCacheMode;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Jpa(
xmlMappings = {
"org/hibernate/orm/test/jpa/cacheable/disableselective/orm.xml",
},
sharedCacheMode = SharedCacheMode.DISABLE_SELECTIVE
)
@JiraKey( "HHH-18041" )
public class DisableCacheTest {
@Test
public void testDisableCache(EntityManagerFactoryScope scope) {
final Long id = 1l;
scope.inEntityManager(
entityManager -> {
entityManager.getTransaction().begin();
try {
City city = new City( id, "Gradoli" );
entityManager.persist( city );
Person person = new Person( "1", "And", "Bor" );
entityManager.persist( person );
entityManager.flush();
entityManager.getTransaction().commit();
}
finally {
if ( entityManager.getTransaction().isActive() ) {
entityManager.getTransaction().rollback();
}
}
Cache cache = entityManager.getEntityManagerFactory().getCache();
assertTrue( cache.contains( City.class, id ) );
assertFalse( cache.contains( Person.class, "1" ) );
}
);
}
}

View File

@ -0,0 +1,43 @@
package org.hibernate.orm.test.jpa.cacheable.disableselective;
public class Person {
private String id;
private String firstName;
private String lastName;
public Person() {
}
public Person(String id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
xmlns="https://jakarta.ee/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence/orm https://jakarta.ee/xml/ns/persistence/orm/orm_3_2.xsd"
version="3.2">
<package>org.hibernate.orm.test.jpa.cacheable.disableselective</package>
<entity name="Person" class="Person" cacheable="false">
<attributes>
<id name="id"/>
<basic name="firstName"/>
<basic name="lastName"/>
</attributes>
</entity>
<entity name="City" class="City" cacheable="true">
<attributes>
<id name="id"/>
<basic name="name"/>
</attributes>
</entity>
</entity-mappings>