|
8 | 8 | import jakarta.persistence.criteria.CriteriaQuery;
|
9 | 9 |
|
10 | 10 | import org.hibernate.SessionFactory;
|
| 11 | +import org.hibernate.engine.spi.SessionLazyDelegator; |
| 12 | +import org.hibernate.engine.spi.SharedSessionContractImplementor; |
11 | 13 | import org.hibernate.query.IllegalMutationQueryException;
|
12 | 14 | import org.hibernate.query.IllegalSelectQueryException;
|
13 | 15 | import org.hibernate.query.Order;
|
|
19 | 21 | import org.hibernate.query.restriction.Restriction;
|
20 | 22 | import org.hibernate.testing.jdbc.SQLStatementInspector;
|
21 | 23 | import org.hibernate.testing.orm.junit.DomainModel;
|
| 24 | +import org.hibernate.testing.orm.junit.JiraKey; |
22 | 25 | import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
23 | 26 | import org.junit.jupiter.api.Test;
|
24 | 27 |
|
@@ -160,6 +163,46 @@ void testSimpleMutationRestriction(SessionFactoryScope factoryScope) {
|
160 | 163 | assertThat( sqlCollector.getSqlQueries().get( 0 ) ).contains( " where be1_0.position between ? and ?" );
|
161 | 164 | }
|
162 | 165 |
|
| 166 | + @Test |
| 167 | + @JiraKey("HHH-19531") |
| 168 | + void testSelectionOnSessionProxy(SessionFactoryScope factoryScope) { |
| 169 | + final SQLStatementInspector sqlCollector = factoryScope.getCollectingStatementInspector(); |
| 170 | + |
| 171 | + factoryScope.inTransaction( (session) -> { |
| 172 | + var sessionProxy = new SessionLazyDelegator( () -> session ); |
| 173 | + // The test only makes sense if this is true. It currently is, but who knows what the future has in store for us. |
| 174 | + //noinspection ConstantValue |
| 175 | + assert !(sessionProxy instanceof SharedSessionContractImplementor); |
| 176 | + |
| 177 | + sqlCollector.clear(); |
| 178 | + SelectionSpecification.create( BasicEntity.class, "from BasicEntity" ) |
| 179 | + .createQuery( sessionProxy ) |
| 180 | + .list(); |
| 181 | + } ); |
| 182 | + |
| 183 | + assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 ); |
| 184 | + } |
| 185 | + |
| 186 | + @Test |
| 187 | + @JiraKey("HHH-19531") |
| 188 | + void testMutationOnSessionProxy(SessionFactoryScope factoryScope) { |
| 189 | + final SQLStatementInspector sqlCollector = factoryScope.getCollectingStatementInspector(); |
| 190 | + |
| 191 | + factoryScope.inTransaction( (session) -> { |
| 192 | + var sessionProxy = new SessionLazyDelegator( () -> session ); |
| 193 | + // The test only makes sense if this is true. It currently is, but who knows what the future has in store for us. |
| 194 | + //noinspection ConstantValue |
| 195 | + assert !(sessionProxy instanceof SharedSessionContractImplementor); |
| 196 | + |
| 197 | + sqlCollector.clear(); |
| 198 | + MutationSpecification.create( BasicEntity.class, "delete BasicEntity" ) |
| 199 | + .createQuery( sessionProxy ) |
| 200 | + .executeUpdate(); |
| 201 | + } ); |
| 202 | + |
| 203 | + assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 ); |
| 204 | + } |
| 205 | + |
163 | 206 | @Test
|
164 | 207 | void testSimpleMutationRestrictionAsReference(SessionFactoryScope factoryScope) {
|
165 | 208 | final SQLStatementInspector sqlCollector = factoryScope.getCollectingStatementInspector();
|
|
0 commit comments