Map mapping

2 Messages Forum Options Options
Embed this topic
Permalink
Andreas Prudzilko
Map mapping
Reply Threaded MoreMore options
Print post
Permalink
Hi,

I have a slight problem with map mappings.

public class Item extends BusinessDomainObject {
    private Map<Attribute, Value> values = new HashMap<Attribute, Value>();
    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    public Map<Attribute, Value> getValues() {        return values;    }
}

and:

public abstract class Value extends DomainObject {
    private Attribute attribute;
    private Item item;

    @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    public Attribute getAttribute() {        return attribute;    }

    @ManyToOne(optional = false)
    public Item getItem() {        return item;    }

This all works quite fine. However when I put a new values into the map,
without checking for old ones. I get duplicated assignments in my join.
The map table is filled correctly but I would like the map to be in
synch with the Value table. Means: it should remove the values that are
assossiated with a given Item over the attribute map.
So what happens now is:

item.getValues().put(a1, v1);
store(item);

then i do:
item.getValues().put(a1, v2);

I would like v1 to be removed from the database automagically. Otherwise
I would need to fetch the old values and update those all the time.
Which is a bit of a hazzle.
Is that possible?

/Andreas

Pinaki Poddar
Re: Map mapping
Reply Threaded MoreMore options
Print post
Permalink
use @ElementDependent annotation.
For further details, please refer [1]
 
[1] http://openjpa.apache.org/builds/latest/docs/manual/manual.html#dependent