I have the following mapping:
<!-- WidgetConfiguration -->
<class name="MyProject.WidgetConfiguration, MyProject" table="WidgetConfigurations">
<id name="Id" column="Id" type="Int64">
<generator class="native" />
</id>
<property name="Name" column="ConfigurationName" />
<map name="Widgets" table="WidgetConfigurationPositions" cascade="all" lazy="false" fetch="select" inverse="true">
<key column="WidgetConfigurationId" />
<index column="TargetId" type="string" />
<one-to-many class="MyProject.WidgetPlacement" />
</map>
</class>
<!-- End WidgetConfiguration -->
<class name="MyProject.WidgetPlacement, MyProject" table="WidgetConfigurationPositions">
<id name="Id" column="Id" type="Int64">
<generator class="native" />
</id>
<many-to-one name="Widget" class="MyProject.Widget, MyProject" column="WidgetId" lazy="false" />
<property name="Target" column="TargetId" not-null="true" />
<map name="Options" table="PlacedWidgetOptions" cascade="all" lazy="false" fetch="select">
<key column="WidgetConfigurationPositionId"/>
<index column="OptionName" type="string" />
<element column="OptionValue" type="string" />
</map>
</class>
And, I have the following bit of code:
public override void Update(WidgetConfiguration obj)
{
using (var session = GetSession())
{
var tx = session.BeginTransaction();
session.Update(obj);
tx.Commit();
//session.Evict(obj);
}
}
I can Save a WidgetConfiguration just dandy, but trying to UPDATE a WidgetConfiguration, NHibernate actually performs an insert! Here is the session from my NHibernate Profiler.
begin transaction with isolation level: Unspecified
INSERT INTO WidgetConfigurations
(ConfigurationName)
VALUES ('dashboard' /* @p0 */)
select SCOPE_IDENTITY()
INSERT INTO WidgetConfigurationPositions
(WidgetId,
TargetId)
VALUES (1 /* @p0 */,
'row1-column1' /* @p1 */)
select SCOPE_IDENTITY()
UPDATE WidgetConfigurationPositions
SET WidgetId = 1 /* @p0 */,
TargetId = 'row1-column2' /* @p1 */
WHERE Id = 356 /* @p2 */
commit transaction
I have no idea why this would be happening and Google is not being very helpful. Anyone have any ideas?