Sorry, I posted it in the wrong forum. Because I partially found the answer, I post it again with the answer. I hope it will help others.
C-Rock
----------------------------------------------------
Hi,
When I insert new records to the database, the "version" field is assigned with the version "1" - I checked the object property value and that's what I expected- and when I commit the field in the DB is null !!!???
I used the generated="always" to avoid yo manage it manually (see the hbm.xml I pasted below). The generator works fine but not the version...
Is someone able to explain why the object property works fine but the field is null in the database?
Hibernate version: 1.2 for .NET 2.0
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DataLayer" namespace="DataLayer.DataObjects">
<class name="FREQUENCY" table="FREQUENCY" optimistic-lock="version" dynamic-update="true" dynamic-insert="true" >
<id name="FREQUENCY_OID" column="FREQUENCY_OID" type="Int32">
<generator class="hilo" />
</id>
<version column="FREQUENCY_RECORD_VERSION" name="FREQUENCY_RECORD_VERSION" type="Int32" generated="always" />
<property name="FREQUENCY_CODE" type="String" length="15" not-null="true"/>
<property name="FREQUENCY_DESCRIPTION" type="String" length="80" not-null="true"/>
<property name="FREQUENCY_VALUE" type="Int32" not-null="true"/>
<property name="FREQUENCY_UNIT" type="String" length="8" not-null="true"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
transaction.Begin();
foreach (String frequency in frequencies)
{
// frequency.FREQUENCY_RECORD_VERSION = null
// Insertion
transaction.Save(frequency);
// frequency.FREQUENCY_RECORD_VERSION =1
}
transaction.Commit();
[b]// But the field in the database is null!!![/b]
Name and version of the database you are using: SQL Server 2005