Note that there are some explanatory texts on larger screens.

plurals
  1. POFluent NHibernate to an in-memory SQLite DB throws exceptions on insert with Version
    text
    copied!<p>I've a rather large domain-model that persists using fluent NHibernate to MS SQL Server 2008.</p> <p>Recently we've been running into concurrency problems, so I implemented Versioning NHibernate's excellent Version with an eye to using MSSQL's <code>timestamp</code>datatype. All my entities subclass the cunningly named <code>DomainEntity</code>abstract class, which has the following <code>IAutoMappingOverride</code>:</p> <pre><code>public class DomainEntityOverride : IAutoMappingOverride&lt;DomainEntity&gt; { public void Override(AutoMapping&lt;DomainEntity&gt; mapping) { mapping.OptimisticLock.Version(); mapping.Version(entity =&gt; entity.Version); } } </code></pre> <p>Furthermore I set up the versioning using an <code>IVersionConvention</code>:</p> <pre><code>public class VersionConvention : IVersionConvention { public void Apply(IVersionInstance instance) { instance.Column("Version"); instance.Generated.Always(); instance.UnsavedValue("null"); instance.Not.Nullable(); instance.CustomSqlType("timestamp"); } } </code></pre> <p>My understanding is that this should cause the Version to always be generated, and checked for concurrency issues. In my dev and production environments (both using MSSQL2008) it seems to work, but my in-memory tests using SQLite no longer work.</p> <p>A basic test that now fails is the following:</p> <pre><code> [Test(Description = "Can save an aircraft and it is persisted")] public void PersistAircraft_NewAircraft_AircraftIsPersisted() { var id = saveEntity(_aircraft); //exception thrown here var persisted = getEntity&lt;Aircraft&gt;(id); Assert.That(persisted.Registration, Is.EqualTo(_aircraftRegistration)); Assert.That(persisted.Remarks, Is.EqualTo(_aircraftRemark)); } </code></pre> <p>I get the follwing exception:</p> <pre><code>Test 'NOIS.Persistence.Tests.InMemory.AircraftPersistenceTest.PersistAircraft_NewAircraft_AircraftIsPersisted' failed: NHibernate.Exceptions.GenericADOException : could not insert: [NOIS.Model.Entities.AircraftType#9c2809ea-c0c5-4778-838b-9e2500a6d2ef][SQL: INSERT INTO "AircraftType" (ProducedBy, Active, Remarks, Name, Code, Category_id, Id) VALUES (?, ?, ?, ?, ?, ?, ?)] ----&gt; System.Data.SQLite.SQLiteException : Abort due to constraint violation AircraftType.Version may not be NULL </code></pre> <p>at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session) at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session) at NHibernate.Action.EntityInsertAction.Execute() at NHibernate.Engine.ActionQueue.Execute(IExecutable executable) at NHibernate.Engine.ActionQueue.ExecuteActions(IList list) at NHibernate.Engine.ActionQueue.ExecuteActions() at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) at NHibernate.Impl.SessionImpl.Flush() at NHibernate.Transaction.AdoTransaction.Commit() FluentlyConfiguredInMemoryDatabaseTest.cs(49,0): at NOIS.Persistence.Tests.FluentlyConfiguredInMemoryDatabaseTest.saveEntity(DomainEntity entity) InMemory\AircraftPersistenceTest.cs(33,0): at NOIS.Persistence.Tests.InMemory.AircraftPersistenceTest.PersistAircraft_NewAircraft_AircraftIsPersisted() --SQLiteException at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt) at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt) at System.Data.SQLite.SQLiteDataReader.NextResult() at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave) at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior) at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery() at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd) at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation) at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload