Using NHibernate 0.9.0.0, runtime 1.1.4322 and Postgresql 8.0 I get a Multiple Assignments to Same Column error. The column in question here is capid.
Basically, as can be seen from the log4net output, Nhibernate is building an UPDATE statement that has capid in it twice. This is assigning the same value twice too. I have been through code, definitions and even changed the database to try and solve this but nothing has prevailed. All the definitions seem in order, and match other objects that work correctly.
It looks like any access to the Uservehicle object attempts to update the Vehicle object with the problem statement. I changed the code so that the two objects were no longer linked, but any use of the two objects in the same session caused the same error - even for simple SELECT constructs.
Has anyone had a similar problem? Why is the UPDATE being generated regardless of the opertation on the parent object?
Definition files and debug level output attached
Uservehicle.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Cara.BusinessObjects.Uservehicle,Cara" table="uservehicle">
<id name="Id" column="id" type="Int32" unsaved-value="null">
<generator class="native"/>
</id>
<property column="userid" type="Int32" name="Userid" not-null="true" />
<property column="usercapid" type="Int32" name="Usercapid" not-null="true" update="false" />
<property column="modified" type="DateTime" name="Modified" not-null="true" />
<many-to-one name="VehicleObj" class="Cara.BusinessObjects.Vehicle, Cara" unique="true" column="usercapid" insert="false" update="false" property-ref="CapId" cascade="none" />
</class>
</hibernate-mapping>
Vehicle.hbm.xmlCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Cara.BusinessObjects.Vehicle,Cara" table="vehicle">
<id name="Id" column="id" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<property column="capid" type="Int32" name="CapId" not-null="true" insert="false" update="false"/>
...
<many-to-one name="CapData" class="Cara.BusinessObjects.CapVehicles, Cara" foreign-key="CvehicleId" unique="true" column="capId"/>
<many-to-one name="Capder" class="Cara.BusinessObjects.Capder, Cara" foreign-key="cder_id" unique="true" column="capId"/>
</class>
</hibernate-mapping>
Error MsgCode:
2006-02-27 13:41:29,982 DEBUG 2616 NHibernate.Impl.SessionImpl - deleting a persistent instance
2006-02-27 13:41:29,982 DEBUG 2616 NHibernate.Impl.SessionImpl - deleting [Cara.BusinessObjects.Uservehicle#6367]
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.SessionImpl - flushing session
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.SessionImpl - Flushing entities and processing referenced collections
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Persister.AbstractEntityPersister - Cara.BusinessObjects.Vehicle.MetallicNet is dirty
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Persister.AbstractEntityPersister - Cara.BusinessObjects.Vehicle.MetallicDiscount is dirty
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.SessionImpl - Updating entity: [Cara.BusinessObjects.Vehicle#2783]
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Persister.AbstractEntityPersister - Cara.BusinessObjects.Capder.CderDiscontinued is dirty
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.SessionImpl - Updating entity: [Cara.BusinessObjects.Capder#29100]
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Persister.AbstractEntityPersister - Cara.BusinessObjects.CapVehicles.CvehicleDerDiscontinued is dirty
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.SessionImpl - Updating entity: [Cara.BusinessObjects.CapVehicles#29100]
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.SessionImpl - Processing unreferenced collections
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.SessionImpl - Processed 0 unreachable collections.
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.SessionImpl - scheduling collection removes/(re)creates/updates
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.SessionImpl - Processed 0 for recreate (0), remove (0), and update (0)
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.SessionImpl - Flushed: 0 insertions, 3 updates, 1 deletions to 6 objects
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.SessionImpl - executing flush
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Persister.EntityPersister - Updating entity: Cara.BusinessObjects.Vehicle#2783
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.BatcherImpl - Opened new IDbCommand, open IDbCommands :1
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.BatcherImpl - Building an IDbCommand object for the SqlString: UPDATE vehicle SET co2Level = :co2Level, derivative = :derivative, firstRegValue = :firstRegValue, delivery = :delivery, model = :model, otrPrice = :otrPrice, manufacturer = :manufacturer, capId = :capId, vrbRate = :vrbRate, metallicNet = :metallicNet, subtotal = :subtotal, introYear = :introYear, capId = :capId, vrbValue = :vrbValue, vehicleDiscount = :vehicleDiscount, special = :special, vehicleDiscountValue = :vehicleDiscountValue, metallicDiscount = :metallicDiscount, fuel = :fuel, metallic = :metallic, listPrice = :listPrice, vat = :vat WHERE id = :id
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Persister.EntityPersister - Dehydrating entity: Cara.BusinessObjects.Vehicle#2783
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '185' to parameter: 0
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '1.8 VVTi Pemium Blue 3dr' to parameter: 1
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '188.0000' to parameter: 2
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '510.0000' to parameter: 3
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding 'CELICA COUPE SPECIAL EDS' to parameter: 4
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '17673.8360' to parameter: 5
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding 'TOYOTA' to parameter: 6
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '29100' to parameter: 7
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '0' to parameter: 8
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '0' to parameter: 9
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '14447.5200' to parameter: 10
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '2004' to parameter: 11
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '29100' to parameter: 12
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '0' to parameter: 13
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '8' to parameter: 14
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding 'False' to parameter: 15
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '1256.3100' to parameter: 16
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '0' to parameter: 17
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding 'P' to parameter: 18
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '297.8700' to parameter: 19
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '15703.8300' to parameter: 20
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '2604.2700' to parameter: 21
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Type.NullableType - binding '2783' to parameter: 22
2006-02-27 13:41:31,669 INFO 2616 NHibernate.Impl.BatcherImpl - Preparing UPDATE vehicle SET co2Level = :p0, derivative = :p1, firstRegValue = :p2, delivery = :p3, model = :p4, otrPrice = :p5, manufacturer = :p6, capId = :p7, vrbRate = :p8, metallicNet = :p9, subtotal = :p10, introYear = :p11, capId = :p12, vrbValue = :p13, vehicleDiscount = :p14, special = :p15, vehicleDiscountValue = :p16, metallicDiscount = :p17, fuel = :p18, metallic = :p19, listPrice = :p20, vat = :p21 WHERE id = :p22
2006-02-27 13:41:31,669 DEBUG 2616 NHibernate.Impl.BatcherImpl - Closed IDbCommand, open IDbCommands :0
2006-02-27 13:41:31,685 ERROR 2616 NHibernate.ADOException - could not synchronize database state with session
Npgsql.NpgsqlException:
multiple assignments to same column "capid"
Severity: ERROR
Code: 42601
at Npgsql.NpgsqlConnector.CheckErrors()
at Npgsql.NpgsqlConnector.CheckErrorsAndNotifications()
at Npgsql.NpgsqlCommand.ExecuteCommand()
at Npgsql.NpgsqlCommand.ExecuteNonQuery()
at NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Boolean[] includeProperty, Object oldVersion, Object obj, SqlString sqlUpdateString, ISessionImplementor session)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledUpdate.Execute()
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()