Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-2040

Database transactions can be committed prematurely when using Cayenne PK generation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.M2
    • 4.0.M5
    • Core Library
    • None
    • MySQL/Derby

    Description

      When using Cayenne PK generation (i.e. AUTO_PK_SUPPORT table) the following test will fail on the last assertion statement with select query returning 20 objects instead of 0:

      TransactionTest.java
      public void testRollbackTransaction() {
      		assertEquals(0, ObjectSelect.query(Artist.class).select(context).size());
      
      		try {
      			runtime.performInTransaction(new TransactionalOperation<Object>() {
      				@Override
      				public Object perform() {
      					for (int i = 0; i < 30; i++) {
      						Artist artist = context.newObject(Artist.class);
      						artist.setArtistName("test" + i);
      
      						context.commitChanges();
      					}
      
      					context.newObject(Artist.class);
      
      					// this should fail with validation error
      					context.commitChanges();
      
      					return null;
      				}
      			});
      		} catch (Exception e) {
      			// ignore
      		}
      
      		assertEquals(0, ObjectSelect.query(Artist.class).select(context).size());
      	}
      

      The culprit seems to be PK generating code committing transaction when advancing AUTO_PK_SUPPORT next_id value.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              demitri Dzmitry Kazimirchyk
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: