Hi there,
I am using the @MapKey annotation to create a map of "properties" for an object and I wanted to have feedback on any best practices. Searching the web and hibernates books yield not result.
What I have basically is an ITEM table with a one to many relationship on a PROPERTY table. The property defines basically a name (String) and a value (could be of multiple type). I use the flat table mapping for this.
In my entity I have something like this
Code:
@OneToMany(
mappedBy = "item",
fetch = FetchType.LAZY,
targetEntity = ItemPropertyEntity.class)
@MapKey(name = "propertyName")
@Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private Map<String, ItemPropertyEntity> properties = new HashMap<String, ItemPropertyEntity>();
I want to expose a meaningful API in the ItemEntity class to add/update and remove ItemProperty instances. Any best practice to do this?
Thanks,
Stéphane