-->
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.  [ 3 posts ] 
Author Message
 Post subject: Unexpected row count: 0; expected: 1
PostPosted: Wed Feb 20, 2008 3:55 pm 
Beginner
Beginner

Joined: Tue Jan 22, 2008 11:33 am
Posts: 46
Hi folks,

looking through the forum no hint has helped me to solve my problem.
I try to connect to various databases - none of them will accept an SaveOrUpdate.
I got a table with an Id column ( no automatic increment).

I have a mapping file
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <!--Mapping Files 2-->
  <class name="ForDBConnectionTest.TestTable,ForDBConnectionTest" table="TestTable" lazy="false">
    <id name="Id" column="ID" type="int">
      <generator class="assigned" />
    </id>
    <property type="string" length="10" name="Description1" column="Description1" />
    <property type="string" length="10" name="Description2" column="Description2" />
  </class>
</hibernate-mapping>


and the following code trys to insert a row to the DB-table.

Code:
TestTable myTest = new TestTable();
            myTest.Id = 4;
            myTest.Description1 = "vier";
            myTest.Description2 = "Anzeige4";
            Program myObject = new Program();
            myObject.Save(myTest);


The Save-Method looks like that:

Code:
public virtual void Save(object item)
      {
         ISession session = SessionProvider.Instance.GetSession();
         ITransaction trans = null;

         try
         {
            trans = session.BeginTransaction();
            session.SaveOrUpdate( item );

            trans.Commit();
         }
         catch (Exception ex)
         {
            trans.Rollback();
            throw new DataAccessException("Error saving item", ex);
         }
         finally
         {
            SessionProvider.Instance.CloseSession();
         }
      }



So it's a SaveOrUpdate which will be executed and where exception is thrown.

Code:
ForDBConnectionTest.DataAccessException wurde nicht behandelt.
  Message="Error saving item"
  Source="ForDBConnectionTest"
  StackTrace:
       bei ForDBConnectionTest.BaseDAO.Save(Object item) in C:\Dokumente und Einstellungen\All Users\Dokumente\Visual Studio 2005\!Generated Code\WindowsApplication1\BaseDAO.cs:Zeile 47.
       bei ForDBConnectionTest.Program.Main() in C:\Dokumente und Einstellungen\All Users\Dokumente\Visual Studio 2005\!Generated Code\WindowsApplication1\Program.cs:Zeile 24.
       bei System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       bei System.Threading.ThreadHelper.ThreadStart()



I tryed to use Save instead of SaveOrUpdate. When I tried another generator class "guid" (got the idea from this link http://blog.maartenballiauw.be/post/2007/07/nhibernate-1-2-0---unexpected-row-count-03b-expected-1.aspx). it works excellent. But I want to assign a own integer number within my coding. Any idea how I can do that.


Thanks antoschka


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 7:07 pm 
Regular
Regular

Joined: Mon Mar 20, 2006 10:49 pm
Posts: 59
If you assign the id yourself, you must use Save(). SaveOrUpdate() can't be used because it has no way to determine whether to do a Save or an Update.

_________________
Mike Abraham


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 7:26 pm 
Beginner
Beginner

Joined: Tue Jan 22, 2008 11:33 am
Posts: 46
Thanks for your reply. Unfortunately the Save method won't do it either. As I said with MS SQL it works fine. Is it possible that some settings of my OLE DB configuation (see above) is wrong?

Thanks in advance

Bye antoschka


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.