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
-~----------~----~----~----~------~----~------~--~---