-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-19142 StatelessSession.getMultiple() and second-level cache
- Loading branch information
Showing
3 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
hibernate-core/src/test/java/org/hibernate/orm/test/stateless/GetMultipleFromCacheTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* Copyright Red Hat Inc. and Hibernate Authors | ||
*/ | ||
package org.hibernate.orm.test.stateless; | ||
|
||
import jakarta.persistence.Cacheable; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
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 java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
@SessionFactory(generateStatistics = true) | ||
@DomainModel(annotatedClasses = GetMultipleFromCacheTest.Record.class) | ||
public class GetMultipleFromCacheTest { | ||
@Test void test(SessionFactoryScope scope) { | ||
scope.inStatelessTransaction(s-> { | ||
s.insert(new Record(123L,"hello earth")); | ||
s.insert(new Record(456L,"hello mars")); | ||
}); | ||
scope.inStatelessTransaction(s-> { | ||
List<Record> all = s.getMultiple(Record.class, List.of(456L, 123L, 2L)); | ||
assertEquals("hello mars",all.get(0).message); | ||
assertEquals("hello earth",all.get(1).message); | ||
assertNull(all.get(2)); | ||
}); | ||
scope.getSessionFactory().getStatistics().clear(); | ||
scope.inStatelessTransaction(s-> { | ||
List<Record> all = s.getMultiple(Record.class, List.of(123L, 2L, 456L)); | ||
assertEquals("hello earth",all.get(0).message); | ||
assertEquals("hello mars",all.get(2).message); | ||
assertNull(all.get(1)); | ||
}); | ||
assertEquals( 2, | ||
scope.getSessionFactory().getStatistics().getSecondLevelCacheHitCount() ); | ||
} | ||
@Entity @Cacheable | ||
static class Record { | ||
@Id Long id; | ||
String message; | ||
|
||
Record(Long id, String message) { | ||
this.id = id; | ||
this.message = message; | ||
} | ||
|
||
Record() { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters