User Tools

Site Tools


This is an old revision of the document!

A PCRE internal error occured. This might be caused by a faulty plugin

====== OpenJPA ====== OpenJPA is a JPA implementation hosted by Apache. ===== Remove Embedded Entity ===== On a One-To-Many relationship the removal of the entities occurs by removing the entities from the list and merging the owner entity. This may lead to an owner entity having no embedded entity. When serializing this case it may lead to a null value for the list which is a valid value. But OpenJPA will ignore the embedded entities in this case and leaves them attached and in relation to the owner entity. The only way to remove all embedded entities seems to set an empty list to the relation attribute. <sxh java> public class ContactPerson { @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval=true) private List<Phone> phones; ... } </sxh> <sxh java> public class ContactPersonService { public ContactPerson update(ContactPerson contactPerson) { if (contactPerson.getPhones() == null) { contactPerson.setPhones(new LinkedList()); } return em.merge(contactPerson); } } </sxh> ===== Links ===== * [[|Apache OpenJPA]] {{tag>java}}

openjpa.1431524768.txt.gz · Last modified: 2015/05/13 13:46 by mihael