I would like to map a LinkedHashMap with Hibernate (annotation driven).
I know the property @MapKey and @IndexColumn, but can I used both to map a linkedhashmap with basics strings ?
Please don’t give a solution where I must externalize pet to a class and use a Pet list instead of a LinkedHashMap (I know how to do that but I clearly don’t want to do this).
my class :
@Entity
public class Person
{
private LinkedHashMap<String, String> pets;
// map definition ?
// id of the pet > name of the pet
public LinkedHashMap<String, String> getPets()
{
return pets;
}
...
}
You may use the
@Lobannotation: the LinkedHashMap will be serialized and stored in a BLOB column (and deserialized when read from the database).But this is of course fragile, impossible to query, forces the use of Java to read the contents of the pets.
If you need a more traditional mapping to an additional Pet table, with a one-to-many association, then you’ll need a Pet entity.