These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: the row was modified or deleted by another user???
PostPosted: Mon Jul 03, 2006 10:00 pm 
Newbie

Joined: Mon Jul 03, 2006 9:31 pm
Posts: 2
Hibernate version:
1.0.2.0
Mapping documents:
Parent.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="HYLQ.Core.Domain.Parent, HYLQ.Core" table="Parent">
<id name="Id" column="Id">
<generator class="assigned" />
</id>
<property name="Title" type="String" length="200" />
<bag name="Childs" lazy="true" inverse="true" cascade= "all-delete-orphan">
<key column="pid" />
<one-to-many class="HYLQ.Core.Domain.Child, HYLQ.Core" />
</bag>
</class>
</hibernate-mapping>

Child.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="HYLQ.Core.Domain.Child, HYLQ.Core" table="Child">
<id name="Id" column="Id">
<generator class="assigned" />
</id>
<property name="Memo" type="String" length="200" />
<many-to-one name="parent" class="HYLQ.Core.Domain.Parent, HYLQ.Core" column="pid" />
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
using (ISession session = TestCategory.Factory.OpenSession())
{
int id = 1;

Parent parent = new Parent();

parent.Id = id;
parent.Title = "tetetet";

Child child = new Child();
child.Id = 1;
child.Memo = "222";
child.parent = parent;

parent.Childs.Add(child);

ITransaction trans = session.BeginTransaction();

try
{
session.Save(parent);
trans.Commit();
}
catch
{
trans.Rollback();
throw;
}
}



Full stack trace of any exception that occurs:

Test method TestProject1.TestCategory.AddParentChild threw exception: NHibernate.HibernateException: SQL insert, update or delete failed (expected affected row count: 1, actual affected row count: 0). Possible causes: the row was modified or deleted by another user, or a trigger is reporting misleading row count..

Name and version of the database you are using:
MS Sql 2000

create table Parent
(
Id int not null,
Title varchar(200) null,
primary key(Id)
)
go

create table Child
(
Id int not null,
pid int not null,
memo varchar(200) null,
primary key(Id)

)
go


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 5:31 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
Can you enable SQL logging? I'm curious to see if an update or insert is being created.

Simply set show_sql=true in your config file.

If you're using the NHibernate config handler then add this:
Code:
<property name="hibernate.show_sql">true</property>


If you're using the name-value handler then add this:
Code:
<add key="hibernate.show_sql" value="false" />


Then, make sure you have log4net set up to capture something... put this in your config if you don't have it already:
Code:
<log4net>
  <appender
    name="rollingFile"
    type="log4net.Appender.RollingFileAppender">
    <file value="c:/log/myAppLog.log" />
    <appendToFile value="true" />
    <rollingStyle value="Date" />
    <datePattern value="yyyyMMdd" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern
        value="--%n%date %-5p(%F:%L)%n Class: %c %n %m %n" />
    </layout>
  </appender>
  <root>
    <priority value="ERROR" />
    <appender-ref ref="rollingFile" />
  </root>

  <logger name="NHibernate.SQL">
    <level value="DEBUG" />
  </logger>
</log4net>


That'll give you the SQL interleaved with the error.... immensely helpful for debugging.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.