Hi. Typically, when an entity has a relationship expressed as @OneToMany or @ManyToMany in a form of a collection, or a map, the collection or a map will be empty (not null), if there are no referenced objects (I believe JPA2.0 explicitly states that). So far, I haven't been having any problems with this, but I did find that the map will be null on a newly merged entity:
ETest test = em.find(ETest.class, req.getParameter(P_ID)); ETest newTest = new ETest(); newTest = em.merge(newTest); newTest.getUsedAgents().putAll(test.getUsedAgents()); newTest = em.merge(newTest); newTest.getUsedAgents().putAll(test.getUsedAgents()); // NPE the getUsedAgents() returns null. The entity code (abridged) is: public class ETest { @ManyToMany(cascade = CascadeType.ALL) private Map<String, EAgent> usedAgents; public Map<String, EAgent> getUsedAgents() { return usedAgents; } } I believe that would be a bug. This is OpenJPA 2.1.1, entities enhanced with PCEnhancer, no funny stuff in p.xml, just the entity list. Thank you, Pawel.