-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to map <Map> with null <map-key-many-to-many>
PostPosted: Thu Aug 03, 2006 2:29 am 
Regular
Regular

Joined: Fri Oct 01, 2004 2:19 am
Posts: 111
Location: Melbourne, Australia
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.

_________________
Cheers,

Bonny

please don't forget to rate :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 04, 2006 1:29 am 
Regular
Regular

Joined: Fri Oct 01, 2004 2:19 am
Posts: 111
Location: Melbourne, Australia
would anyonle like to comment on my question above?

I went ahead and modified the signature of the readIndex method in
CollectionPersister and its only implementation in AbstractCollectionPersister
to specify whether a null index is allowed and tried a couple of my test
cases without seemingly breaking anything; however I don't have the
confidence to tell that this has indeed no impact and I would like if someone
whose closer to Hibernate to comment and perhaps offer an alternative
suggestion if what I want to do is a no no.

_________________
Cheers,

Bonny

please don't forget to rate :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 04, 2006 9:08 pm 
Regular
Regular

Joined: Fri Oct 01, 2004 2:19 am
Posts: 111
Location: Melbourne, Australia
anyone?

I'll be happy even with a negative and reasoned answer. I'm sure there
are enough people out there who know enough to comment.

_________________
Cheers,

Bonny

please don't forget to rate :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 8:27 pm 
Regular
Regular

Joined: Fri Oct 01, 2004 2:19 am
Posts: 111
Location: Melbourne, Australia
help, please ...

_________________
Cheers,

Bonny

please don't forget to rate :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.