It seems as if the insert is completed successfully , but the item is never actually inserted into the table.
If I do a console dump immediately after the insert, it shows the item as being inserted, but when I do a show data on the table, it does not reflect this change.
If I select "Show Table Data" the changes aren't reflected, but I initiate a new insert and query within server explorer then it reflects the proper changes.
Project on GITHUB : https://github.com/Fabii23/NHibernate.git
SQL output:
INSERT INTO Products (Name, Category, Discontinued) VALUES (@p0, @p1
, @p2);@p0 = 'Barley and Oats' [Type: String (0)], @p1 = 'Grains' [Type: String
(0)], @p2 = 0 [Type: Int32 (0)]
NHibernate: select @@IDENTITY
try
{
//Try an insert
using (ISession session = NHibernateTest.NHibernateHelper.GetCurrentSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
int _bool = 1;
var product = new Product("Wonder Bread", "Bread", _bool);
session.Save(product);
transaction.Commit();
}
}
}
catch (Exception e)
{
Console.WriteLine("Error occurred :" + e.Message);
Console.WriteLine("Error occurred :" + e);
}
}
Note that Id autoincrements
Table columns:
int Id | string Name | string Category | bit Discontinued |
Sql output :
NHibernate: INSERT INTO Products (Name, Category, Discontinued) VALUES (@p0, @p1
, @p2);@p0 = 'Wonder Bread' [Type: String (0)], @p1 = 'Bread' [Type: String (0)]
, @p2 = 1 [Type: Int32 (0)]
NHibernate: select @@IDENTITY
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="HibernateExample" namespace="HibernateExample.Domain" >
<class name="Product" table="Products">
<id name="Id" type="integer">
<generator class="identity"/>
</id>
<property name="Name" type="string"/>
<property name="Category" type="string"/>
<property name="Discontinued" />
</class>
</hibernate-mapping>
Hibernate specs:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="connection.driver_class"> NHibernate.Driver.SqlServerCeDriver</property>
<property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
<property name="connection.connection_string">Data Source=FirstSample.sdf;</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>