-->
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.  [ 3 posts ] 
Author Message
 Post subject: mapping a Map containing a Set (Map<K, Set<V>>)
PostPosted: Tue Jan 16, 2007 9:25 am 
Newbie

Joined: Tue Jan 16, 2007 8:58 am
Posts: 3
Hi all,

I am trying to figure out the mapping configuration for a map containing a set. The schema I would like is:

create table entity (id bigint not null, primary key (id));
create table key (id bigint not null, primary key (id));
create table entity_key_values (entity_id bigint not null, key_id bigint not null, value integer not null);

And the field in the entity that I want to map would be:

Code:
class Entity {
...
Map<Key, Set<Integer>> keyValues = new ...;
...
};


Note that in my case, I do not wish there to be a unique constraint on the entity_key_values table for the entity_id & key_id pair, as there should be multiple rows that will all have different values to be mapped into the Set.

I am using annotations, and I can map a simple Map<Key, Integer> to this schema, using:

Code:
@CollectionOfElements
@JoinTable(
    name = "entity_key_values",
    joinColumns = @JoinColumn(name="entity_id")
)
@Column(name="value", nullable=false)
@MapKeyManyToMany(targetEntity=Key.class,
    joinColumns = @JoinColumn(name="key_id")
)
Map<Key, Integer> keyValues = new ...;


But this (of course) this creates the entity_key_values join table with a primary key (unique) constraint on entity_id & key_id. And it doesn't work at all if I put the Set<> around Integer.

Any thoughts? If this isn't possible using annotations, is it possible using the xml configuration?

Also, if this mapping IS possible, can the value be a non-primitive type (eg. a Component or another Entity rather than a integer)?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 5:05 pm 
Newbie

Joined: Tue Jan 16, 2007 8:58 am
Posts: 3
I'm also wondering if this would be possible if the Set<V> was a field of a mapped entity - but then is it possible to have a collection field take it's values from multiple rows of the same table as the entity itself?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 9:12 am 
Newbie

Joined: Tue Jan 16, 2007 8:58 am
Posts: 3
I'm also wondering if a mapping of map containing set would be possible if there was a second join table, as in:

create table entity (id bigint not null, primary key (id));
create table key (id bigint not null, primary key (id));
create table entity_key (id bigint not null, entity_id bigint not null, key_id bigint not null);
create table entity_key_value(entity_key_id bigint not null, value integer not null);

So the relationship between Entity and the entity_key join table would be one to many, and the join table to Key would be many to one, and then there would be a one to many relationship from the entity_key join table to the entity_key_value join table.

I've been doing a lot of searching though, and I'm beginning to think this might be a bit esoteric (although it seems pretty straight forward to me). Should it be a feature request?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.