1 | try {
↵ | | 1 | try {↵
|
2 | // The new membership is transient (it has a null surrogate ID), so↵ | | 2 | ↵
|
3 | // Hibernate assumes that it should be added to the collection.↵ | | |
|
4 | // Inserts are done before deletes, so a ConstraintViolationException↵ | | |
|
5 | // will be thrown on the insert because the unique constraint on the↵ | | |
|
6 | // user and group IDs in the join table is violated. See HHH-2801.↵ | | |
|
7 | s.merge( getUser() );
↵ | | 3 | s.merge( entity );↵
|
8 | s.getTransaction().commit();
↵ | | 4 | s.getTransaction().commit();↵
|
9 | fail( "should have failed because inserts are before deletes");
↵ | | 5 | fail( "was expecting staleness error" );↵
|
10 | }
↵ | | 6 | }↵
|
11 | catch( ConstraintViolationException ex ) {
↵ | | 7 | catch ( StaleObjectStateException expected ) {↵
|
12 | // expected
↵ | | 8 | // expected outcome...↵
|
| | | 9 | }↵
|
| | | 10 | finally {↵
|
13 | s.getTransaction().rollback();↵ | | 11 | s.getTransaction().rollback();↵
|
14 | }↵ | | |
|
15 | finally {
↵ | | |
|
16 | s.close();
↵ | | 12 | s.close();↵
|
17 | } | | 13 | }
|