Hello,
I try to delete an item from a hash map with hibernate.
Here is my config on the collection:
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@OneToMany(mappedBy = "game", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@Where(clause = "charactType='charact'")
@MapKey(name = "shortcut")
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public Map<String, Characteristic> getCharacteristics()
{
return characteristics;
}
public void setCharacteristics(Map<String, Characteristic> characteristics)
{
this.characteristics = characteristics;
}
and here is my remove function on the same object:
@Transactional
public void removeCharacteristic(Characteristic charact)
{
// getCharacteristics().size();
getCharacteristics().remove(charact.getShortcut());
}
Using the removeCharacteristic do not delete the item in database. If I uncomment the line to get the size of the list (which force load of the collection), the record is well deleted.
What is the problem ? how can I achieve it without forcing the load of the entire collection ?
thanks
EDIT: I replace the map by a List, and it runs like a charm (without loading it previously by the size() function)... This is very strange. So my problem is solved with the list, but I'm curious to know why it does not run ?