@@ -40,7 +40,8 @@ protected String getBaseForMappings() {
40
40
41
41
@ Test
42
42
public void test () throws Exception {
43
- doInHibernate ( this ::sessionFactory , session -> {
43
+ VehicleContract contract = doInHibernate ( this ::sessionFactory , session -> {
44
+ VehicleContract firstCotract = null ;
44
45
for ( long i = 0 ; i < 10 ; i ++ ) {
45
46
VehicleContract vehicleContract = new VehicleContract ();
46
47
Vehicle vehicle1 = new Vehicle ();
@@ -53,25 +54,31 @@ public void test() throws Exception {
53
54
session .save ( vehicle2 );
54
55
session .save ( vehicleContract );
55
56
session .save ( vehicleTrackContract );
57
+ if ( i == 0 ) {
58
+ firstCotract = vehicleContract ;
59
+ }
56
60
}
61
+ return firstCotract ;
62
+ } );
57
63
64
+ doInHibernate ( this ::sessionFactory , session -> {
58
65
List workingResults = session .createQuery (
59
66
"select rootAlias.id from Contract as rootAlias where rootAlias.id = :id" )
60
- .setParameter ( "id" , 1L )
67
+ .setParameter ( "id" , contract . getId () )
61
68
.getResultList ();
62
69
63
70
assertFalse ( workingResults .isEmpty () );
64
71
Long workingId = (Long ) workingResults .get ( 0 );
65
- assertEquals ( Long .valueOf ( 1 ), workingId );
72
+ assertEquals ( Long .valueOf ( contract . getId () ), workingId );
66
73
67
74
List failingResults = session .createQuery (
68
75
"select rootAlias.id, type(rootAlias) from Contract as rootAlias where rootAlias.id = :id" )
69
- .setParameter ( "id" , 1L )
76
+ .setParameter ( "id" , contract . getId () )
70
77
.getResultList ();
71
78
72
79
assertFalse ( failingResults .isEmpty () );
73
80
Long failingId = (Long ) ( (Object []) failingResults .get ( 0 ) )[0 ];
74
- assertEquals ( Long .valueOf ( 1 ), failingId );
81
+ assertEquals ( Long .valueOf ( contract . getId () ), failingId );
75
82
} );
76
83
}
77
84
}
0 commit comments