You can manually create the id at object creation (works better with guids as they are guaranteed to be unique), and add a version tag to the xml file.
Therefore, it would look something like this:
Code:
public class OrderItem {
// Fields
private Guid m_ID = Guid.NewGuid();
private int Version = -1;
// Properties
public Guid ID {
get { return this.m_ID; }
}
...
}
and your mapping file would have the following :
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="..." table="OrderItem">
<id name="ID" column="ID" type="Guid">
<generator class="assigned"/>
</id>
<version name="Version" access="field" unsaved-value="-1"/>
...
</class>
</hibernate-mapping>
Note: you need to add the version field to your table. You can also use a timestamp instead of the version...
So when persisting the object, nhibernate will see that you manually assigned the id and will instead verify the unsaved-value of either the version or timestamp.