Title: composite-id nullability rules

It seems that composite-id's are implemented using components.  Now hibernate (version 2.0.3) only considers the component itself null, if all the component's columns are null.  This makes sense in the context of a component within an entity.  However, in the context of a composite-id we currently have a situation where the behaviour should be the opposite - the composite-id instance should be null if any of the columns are null (we are mapping to an existing database).

Consider the following mapping:

    <class name="Thing" table="thing" mutable="false">
        <composite-id name="id">
                <key-property name="databaseName" column="database_name"/>
                <key-property name="id" column="thing_id"/>           
        </composite-id>
       
        <many-to-one name="masterThing" update="false" insert="false">
                <column name="database_name"/>
                <column name="master_thing_id"/>
        </many-to-one>
    </class>


Here we have a self-referencing entity with a composite-id.  A Thing can only have a masterThing that has the same databaseName, so the database_name column is re-used in both the primary key & foreign key.  Now, when a Thing does not have a masterThing, the database_name column will not be null (as, it is also part of the primary key), but the master_thing_id column will be null.  Conversely, a Thing only has a masterThing when both columns are not null.

I figure that we could:
1. Change the nullability behaviour of composite-id's.
2. Add another attribute to the composite-id element in the mapping file to specifiy the behaviour.

Thoughts, comments?

Regards
_______________________________
brad clow
chief technical officer
workingmouse

email: [EMAIL PROTECTED]
web:   http://www.workingmouse.com

Reply via email to