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