@@ -228,7 +228,10 @@ public void InsertWithGeneratedVersionAndId()
228
228
229
229
s = OpenSession ( ) ;
230
230
t = s . BeginTransaction ( ) ;
231
- int count = s . CreateQuery ( "insert into IntegerVersioned ( name ) select name from IntegerVersioned" ) . ExecuteUpdate ( ) ;
231
+ int count =
232
+ s . CreateQuery ( "insert into IntegerVersioned ( name, Data ) select name, Data from IntegerVersioned where id = :id" )
233
+ . SetInt64 ( "id" , entity . Id )
234
+ . ExecuteUpdate ( ) ;
232
235
t . Commit ( ) ;
233
236
s . Close ( ) ;
234
237
@@ -277,7 +280,10 @@ public void InsertWithGeneratedTimestampVersion()
277
280
s = OpenSession ( ) ;
278
281
t = s . BeginTransaction ( ) ;
279
282
int count =
280
- s . CreateQuery ( "insert into TimestampVersioned ( name ) select name from TimestampVersioned" ) . ExecuteUpdate ( ) ;
283
+ s . CreateQuery (
284
+ "insert into TimestampVersioned ( name, Data ) select name, Data from TimestampVersioned where id = :id" )
285
+ . SetInt64 ( "id" , entity . Id )
286
+ . ExecuteUpdate ( ) ;
281
287
t . Commit ( ) ;
282
288
s . Close ( ) ;
283
289
@@ -393,59 +399,81 @@ public void UpdateWithWhereExistsSubquery()
393
399
[ Test ]
394
400
public void IncrementCounterVersion ( )
395
401
{
396
- ISession s = OpenSession ( ) ;
397
- ITransaction t = s . BeginTransaction ( ) ;
402
+ IntegerVersioned entity ;
398
403
399
- var entity = new IntegerVersioned { Name = "int-vers" } ;
400
- s . Save ( entity ) ;
401
- t . Commit ( ) ;
402
- s . Close ( ) ;
404
+ using ( ISession s = OpenSession ( ) )
405
+ using ( ITransaction t = s . BeginTransaction ( ) )
406
+ {
407
+ entity = new IntegerVersioned { Name = "int-vers" , Data = "foo" } ;
408
+ s . Save ( entity ) ;
409
+ t . Commit ( ) ;
410
+ }
403
411
404
412
int initialVersion = entity . Version ;
405
413
406
- s = OpenSession ( ) ;
407
- t = s . BeginTransaction ( ) ;
408
- int count = s . CreateQuery ( "update versioned IntegerVersioned set name = name" ) . ExecuteUpdate ( ) ;
409
- Assert . That ( count , Is . EqualTo ( 1 ) , "incorrect exec count" ) ;
410
- t . Commit ( ) ;
414
+ using ( ISession s = OpenSession ( ) )
415
+ {
416
+ using ( ITransaction t = s . BeginTransaction ( ) )
417
+ {
418
+ // Note: Update more than one column to showcase NH-3624, which involved losing some columns. /2014-07-26
419
+ int count = s . CreateQuery ( "update versioned IntegerVersioned set name = concat(name, 'upd'), Data = concat(Data, 'upd')" )
420
+ . ExecuteUpdate ( ) ;
421
+ Assert . That ( count , Is . EqualTo ( 1 ) , "incorrect exec count" ) ;
422
+ t . Commit ( ) ;
423
+ }
424
+
425
+ using ( ITransaction t = s . BeginTransaction ( ) )
426
+ {
427
+ entity = s . Get < IntegerVersioned > ( entity . Id ) ;
428
+ s . Delete ( entity ) ;
429
+ t . Commit ( ) ;
430
+ }
431
+ }
411
432
412
- t = s . BeginTransaction ( ) ;
413
- entity = s . Load < IntegerVersioned > ( entity . Id ) ;
414
433
Assert . That ( entity . Version , Is . EqualTo ( initialVersion + 1 ) , "version not incremented" ) ;
415
-
416
- s . Delete ( entity ) ;
417
- t . Commit ( ) ;
418
- s . Close ( ) ;
434
+ Assert . That ( entity . Name , Is . EqualTo ( "int-versupd" ) ) ;
435
+ Assert . That ( entity . Data , Is . EqualTo ( "fooupd" ) ) ;
419
436
}
420
437
421
438
[ Test ]
422
439
public void IncrementTimestampVersion ( )
423
440
{
424
- ISession s = OpenSession ( ) ;
425
- ITransaction t = s . BeginTransaction ( ) ;
441
+ TimestampVersioned entity ;
426
442
427
- var entity = new TimestampVersioned { Name = "ts-vers" } ;
428
- s . Save ( entity ) ;
429
- t . Commit ( ) ;
430
- s . Close ( ) ;
443
+ using ( ISession s = OpenSession ( ) )
444
+ using ( ITransaction t = s . BeginTransaction ( ) )
445
+ {
446
+ entity = new TimestampVersioned { Name = "ts-vers" , Data = "foo" } ;
447
+ s . Save ( entity ) ;
448
+ t . Commit ( ) ;
449
+ }
431
450
432
451
DateTime initialVersion = entity . Version ;
433
452
434
453
Thread . Sleep ( 1300 ) ;
435
454
436
- s = OpenSession ( ) ;
437
- t = s . BeginTransaction ( ) ;
438
- int count = s . CreateQuery ( "update versioned TimestampVersioned set name = name" ) . ExecuteUpdate ( ) ;
439
- Assert . That ( count , Is . EqualTo ( 1 ) , "incorrect exec count" ) ;
440
- t . Commit ( ) ;
455
+ using ( ISession s = OpenSession ( ) )
456
+ {
457
+ using ( ITransaction t = s . BeginTransaction ( ) )
458
+ {
459
+ // Note: Update more than one column to showcase NH-3624, which involved losing some columns. /2014-07-26
460
+ int count = s . CreateQuery ( "update versioned TimestampVersioned set name = concat(name, 'upd'), Data = concat(Data, 'upd')" )
461
+ . ExecuteUpdate ( ) ;
462
+ Assert . That ( count , Is . EqualTo ( 1 ) , "incorrect exec count" ) ;
463
+ t . Commit ( ) ;
464
+ }
465
+
466
+ using ( ITransaction t = s . BeginTransaction ( ) )
467
+ {
468
+ entity = s . Load < TimestampVersioned > ( entity . Id ) ;
469
+ s . Delete ( entity ) ;
470
+ t . Commit ( ) ;
471
+ }
472
+ }
441
473
442
- t = s . BeginTransaction ( ) ;
443
- entity = s . Load < TimestampVersioned > ( entity . Id ) ;
444
474
Assert . That ( entity . Version , Is . GreaterThan ( initialVersion ) , "version not incremented" ) ;
445
-
446
- s . Delete ( entity ) ;
447
- t . Commit ( ) ;
448
- s . Close ( ) ;
475
+ Assert . That ( entity . Name , Is . EqualTo ( "ts-versupd" ) ) ;
476
+ Assert . That ( entity . Data , Is . EqualTo ( "fooupd" ) ) ;
449
477
}
450
478
451
479
[ Test ]
0 commit comments