User Tools

Site Tools


openjpa

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. ===== Default Fetch Type ===== OpenJPA seems to have FetchType.LAZY as a default. Other JPA implementations have other defaults, f. e. EclipseLink. Keep in mind to explicitly set the fetch type for relations if you want them loaded immediately. ===== 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 ===== * [[http://openjpa.apache.org|Apache OpenJPA]] {{tag>java}}

openjpa.1431524885.txt.gz · Last modified: 2015/05/13 13:48 by mihael