Database: Microsoft SQL Server 2000
Hibernate version: NHibernate 1.2.0
Hibernate mapping version: 2.2
.NET version: 2.0
Visual studio version: 2005
Hi all,
(First you will see the description of our situation, my question is formulated at the end of the post)
We use versioning for optimistic locking (MSSQL timestamp column) in each table in the database that contains editable data. In the NHibernate mapping the
version-tag is used to support the versioning. This feature works excellent in NHibernate as such.
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="true" namespace="..." assembly="...">
<class name="..." table="..." lazy="true" optimistic-lock="version">
...
<version name="_Version" column="Version" type="..." generated="always" unsaved-value="null" />
...
</class>
</hibernate-mapping>
We are also using Inheritance Mapping to map our contact-mechanism in our database (contact-mechanism = entity that represents a way to contact a person). This feature works fine as such.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="true" namespace="..." assembly="...">
<class name="ContactMechanism" table="ContactMechanism" lazy="true" optimistic-lock="version">
<id name="_ContactMechanismId" column="ContactMechanismId" type="..." unsaved-value="...">
<generator class="..."/>
</id>
<version name="_Version" column="Version" type="..." generated="always" unsaved-value="null" />
<property column="Comment" type="String" name="_Comment" length="200" />
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="true" namespace="..." assembly="...">
<joined-subclass name="Address" table="Address" lazy="true" extends="ContactMechanism">
<key column="ContactMechanismId" />
...
</joined-subclass>
</hibernate-mapping>
Unfortunately versioning can only be mapped inside a
class-tag of the Hibernate 2.2 schema,
and not in the joined-subclass-tag.
This means in case of our contact-mechanism that only the base-class (and base-table) can contain a version field, and that all derived classes (and tables) can not.
Nevertheless both base and derived classes need a version field because they both contain editable data and each of them could be edited separately from outside the application scope.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="true" namespace="..." assembly="...">
<joined-subclass name="Address" table="Address" lazy="true" extends="ContactMechanism">
<key column="ContactMechanismId" />
<!-- version-tag is not allowed here -->
...
</joined-subclass>
</hibernate-mapping>
To complete the description of our situation, here is the database schema of the contact-mechanism:
and the class diagram of the contact-mechanism:
Now here is my question:
Is there is no need for a version-tag in the joined-subclass-tag? In other words: Is my database structure wrong?
- OR -
Is this a limitation of (N)Hibernate? In other words: Can this particular case not be handled by (N)Hibernate?
Will it purhaps in the future???
Any help on this topic will be very much appreciated and thank you for reading my post.
ds38
Ghent
Belgium