|
29 | 29 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
30 | 30 | import static org.junit.jupiter.api.Assertions.assertNotSame; |
31 | 31 | import static org.junit.jupiter.api.Assertions.assertNull; |
| 32 | +import static org.junit.jupiter.api.Assertions.assertSame; |
32 | 33 |
|
33 | 34 | /** |
34 | 35 | * @author Gavin King |
@@ -58,7 +59,7 @@ public void testNaturalIdNullability(SessionFactoryScope scope) { |
58 | 59 |
|
59 | 60 | @AfterEach |
60 | 61 | public void dropTestData(SessionFactoryScope scope) { |
61 | | - scope.getSessionFactory().getSchemaManager().truncate(); |
| 62 | + scope.dropData(); |
62 | 63 | } |
63 | 64 |
|
64 | 65 | @Test |
@@ -362,4 +363,41 @@ public void testEviction(SessionFactoryScope scope) { |
362 | 363 | } |
363 | 364 | ); |
364 | 365 | } |
| 366 | + |
| 367 | + @Test |
| 368 | + @JiraKey("HHH-7287") |
| 369 | + public void testModificationInOtherSession(SessionFactoryScope factoryScope) { |
| 370 | + factoryScope.inTransaction( (session) -> { |
| 371 | + User u = new User( "gavin", "hb", "secret" ); |
| 372 | + session.persist( u ); |
| 373 | + } ); |
| 374 | + |
| 375 | + // Use transactionless session |
| 376 | + factoryScope.inSession( (session) -> { |
| 377 | + // this loads the state into this `session` |
| 378 | + var byNaturalId = session.byNaturalId( User.class ).using( "name", "gavin" ).using( "org", "hb" ).load(); |
| 379 | + assertNotNull( byNaturalId ); |
| 380 | + |
| 381 | + // CHANGE natural-id values in another session |
| 382 | + factoryScope.inTransaction( (otherSession) -> { |
| 383 | + var u = otherSession.find( User.class, 1 ); |
| 384 | + u.setOrg( "zz" ); |
| 385 | + } ); |
| 386 | + // CHANGE APPLIED |
| 387 | + |
| 388 | + byNaturalId = session.byNaturalId( User.class ) |
| 389 | + .using( "name", "gavin" ) |
| 390 | + .using( "org", "hb" ).load(); |
| 391 | + assertNotNull( byNaturalId ); |
| 392 | + |
| 393 | + // the internal query will 'see' the new values, because isolation level < SERIALIZABLE |
| 394 | + var byNaturalId2 = session.byNaturalId( User.class ) |
| 395 | + .using( "name", "gavin" ) |
| 396 | + .using( "org", "zz" ).load(); |
| 397 | + assertSame( byNaturalId, byNaturalId2 ); |
| 398 | + |
| 399 | + // this fails, that's the bug |
| 400 | + assertNotNull( session.byNaturalId( User.class ).using( "name", "gavin" ).using( "org", "hb" ).load()); |
| 401 | + } ); |
| 402 | + } |
365 | 403 | } |
0 commit comments