Just if anyone is interested: I've just added insert="false" and
update="false" to the many-to-one references. Now I manage the foreign
keys by an internal logic of the business objects and map these
foreign keys as normal properties with insert and update mapping.

It works. I was confused, because I didn't find anything about these
attributes for many-to-one references in the documentation...


On 17 Apr., 10:04, "Fred F." <[email protected]> wrote:
> Hello folks,
>
> I need your help again. I'm having a problem with some many-to-many
> references which are using the same foreign keys. I will explain:
>
> Class 'shelter' has two many-to-many references. One is pointing to
> class 'dog' and one to class 'cat'. Shelter can only be used by one
> cat or one dog (there is only space for one in it). Cats and dogs are
> both inheriting from their base class 'animal'. Dogs and cats are both
> stored in a databasetable 'animal' and their types are distinguished
> by an secondary key ('classValue' - see mapping below).
> When I'm reading my class 'shelter' object I do have the correct many-
> to-one associations, because of the composite-id. Either I get an
> element in the dog-reference or I get an element in the cat-reference.
>
> But when I'm trying to insert a class 'shelter' object, I'll get an
> IndexOutOfRangeException, because the OracleParameterCollection has
> got only 'n' elements, but nhibernate tries to add 'n+2' Elements.
>
> I have to mention that I do _not_ map the used foreign keys as a
> normal property in addition and I know, if I did so I had to add the
> 'update=false' and 'insert=false' attributes. But as I'm using the
> foreign keys twice in one mapping, I'm wondering if there is an
> equivalent to the 'update=false' and 'insert=false' for many-to-one
> references.
>
> Mapping for class 'shelter':
> [...]
> <class name="shelter" table="shelter">
>     <composite-id>
>       <key-property name="customid" column="ID" />
>       <key-property name="classValue" column="CLASS" />
>     </composite-id>
>     <property name="xyz" column="xyz" type="String" />
>     <many-to-one name="ref_dog" class="dog" not-found="ignore">
>       <column name="animalId" />
>       <column name="animalType" />
>     </many-to-one>
>     <many-to-one name="ref_cat" class="cat" not-found="ignore">
>       <column name="animalId" />
>       <column name="animalType" />
>     </many-to-one>
>   </class>
> [...]
>
> Mapping for dogs
> [...]
>   <class name="dog" table="animal" lazy="true">
>     <composite-id>
>       <key-property name="customid" column="ID" />
> <!-- for dogs this is always '42' -->
>       <key-property name="classValue" column="CLASS" />
>     </composite-id>
>     <property name="xyz" column="xyz" type="String" />
>   </class>
> [...]
>
> Mapping for cats
> [...]
>   <class name="cat" table="animal" lazy="true">
>     <composite-id>
>       <key-property name="customid" column="ID" />
>       <key-property name="classValue" column="CLASS" />
>     </composite-id>
>     <property name="abc" column="abc" type="String" />
>   </class>
> [...]
>
> I'm using NHibernate 2.0.1.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to