Hibernate version: 3.1
I'm trying to create a map for the following
Code:
class DomainObject
{
int id;
Map< AddressKey, AddressAttributes> addresses
}
class AddressKey
{
int id;
}
class AddressAttributes
{
int id;
AddressKey key;
String attr1;
String attr2;
String attr3;
}
using the following hibernate mapping:
Code:
<class name="DomainObject" table="DOM_OBJ" discriminator-value="DO">
<id> ... </id>
<map name="addresses" table="ADDRESSES">
<key column="DOBJ_ID"/>
<map-key-many-to-many column="ADDR_KEY_ID" class="AddressKey"/>
<one-to-many class="AddressAttributes"/>
</map>
</class>
Everything works fine until I'm trying to use a null value for the map key.
I can add elements to the map, including the one with the null key,
I can persiste those objects.
I cannot however read those objects back, getting a 'null index column ...' exception.
The underlying map in PersistentMap certainly allows for null keys so
why is Hibernate rejecting this? Each of the enities has its own surrogate
key and there's no index on the AddressAttributes table that includes
the AddressKey. The problem seems to be with AbstractCollectionPersister
which checks for a null index since its the same code for maps as it is
for lists/arrays, but IMHO the two are not the same - one has keyed
access( the map) and the other has indexed access (list/array).
The business case for this particular use case has to to with specifying a
some sort of fallback or default map element when no AddressKey can
be specified.
Can I accomplish what I wish to achieve here? Are there alternative ways
to achieve this?
Note I am trying to do this without havind an association table.