English 中文(简体)
为什么NHibernate表演了INSERT而不是更新?
原标题:Why is NHibernate performing an INSERT instead of an update?

我有以下地图:

<!-- 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>

而且,我有以下法典:

public override void Update(WidgetConfiguration obj)
{
 using (var session = GetSession())
 {
  var tx = session.BeginTransaction();
  session.Update(obj);
  tx.Commit();

  //session.Evict(obj);
 }
}

我可以拯救一个仅靠丹迪的植被结构,但试图乌普罗维登一个植被结构,NHibernate实际上做一个插入! 这里是我的国家自由简介会。

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

我有no的想法,这就是为什么会发生这种情况,谷歌也没有多大帮助。 没有人有什么想法?

问题回答

2. 确定无价值特性:

<id name="Id" column="Id" type="Int64" unsaved-value="0">
    <generator class="native" />
</id>

识别栏的类型如何? 如果时间长? 然后,未挖掘价值应为<代码>null。 你们不需要确定这一点,但这是我所尝试的第一个事情。

你们是否记住要超越你们的平等原则和习俗? 由于你正在打耳,然后重新投入这些方法。

我建议采取新行动,并读写持久性生命周期:

我的guess是,你的问题是由在一次国家卫生会议上重新找回该物体,并在另一场会议上加以更新造成的。

要么在整个请求期间举行全国卫生会议,要么试图附上(Lock()?)对更新国家卫生会议提出的反对。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签