Hi,
I have some Entities that are mapped to POJOs. And to each of them I have an Entity that I save with a session of type EntityMode.MAP that have a persistent relation to the corresponding POJO-mapped entity.
Example:
I have a class Person that is persisted via hibernate.
Sometimes I want to create something I call PersonDetail which is persisted by creating a map with its attributes and then persisted in its own database table with a session in EntityMode.MAP.
Problem:
Now, the PersonDetail has a many-to-one relationship to Person. When I create the PersonDetail, I have the associated Person loaded into my Person POJO. Now I need to put this relationship into my map
Person person = ...;
Map<String,Object> versionMap = new HashMap<String,Object>();
versionMap.put("info","test");
versionMap.put("person",pojoToMap(person));
session.save(versionMap);
Question:
What must the "pojoToMap" method do? It can't just return the pojo since I need a map for EntityMode.MAP. But is it sufficient to return a map that only contains "$type$" and "id"? And if I call this method twice for the same person, must I return the same map or just one with identical values?
thanks in advance for any help.
Dirk
|