Skip to content

SequenceStyleGenerator generates Ids twice on SQLite #1429

@jrauber

Description

@jrauber

The SequenceStyleGenerator produces identifiers which are not unique when the increment is happening inside a transaction that is rollbacked later on and SQLite is used.

SequenceStyleGenerator set to:

  • increment_size - 2
  • initial_value - 1
  • optimizer - pooled

The resulting sequence is:

  • Id: 1 - [A001] - Committed
  • Id: 2 - [A002] - Committed
  • Id: 3 - [B001] - Rollback
  • Id: 4 - [C000] - Committed
  • Id: 3 - [C001] - Committed
  • Id: 4 - [C002] - Committed

Test-Case:

[Test]
public void SequenceStyleGeneratorGeneratesIdTwiceOnSQLiteWhenIncrementIsHappeningOnRollback()
{
	var generatedIds = new List<string>();

	using (var session = OpenSession())
	using (var transaction = session.BeginTransaction(IsolationLevel.ReadCommitted))
	{
		for (int i = 1; i <= 2; i++)
		{
			var entry = new Entity { Name = $"A" + i.ToString("000") };

			session.Save(entry);

			generatedIds.Add($"Id: {entry.Id} - [{entry.Name}] - Committed");
		}

		transaction.Commit();
	}

	using (var session = OpenSession())
	using (var transaction = session.BeginTransaction(IsolationLevel.ReadCommitted))
	{
		var entry = new Entity { Name = $"B" + 1.ToString("000") };

		session.Save(entry);

		generatedIds.Add($"Id: {entry.Id} - [{entry.Name}] - Rollback");
		
		transaction.Rollback();
	}

	Assert.Throws<GenericADOException>(() => {

		for (int i = 0; i < 5; i++)
		{
			using (var session = OpenSession())
			using (var transaction = session.BeginTransaction(IsolationLevel.ReadCommitted))
			{
				var entry = new Entity { Name = $"C" + i.ToString("000") };

				session.Save(entry);

				generatedIds.Add($"Id: {entry.Id} - [{entry.Name}] - Committed");

				transaction.Commit();
			}
		}

	});

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions