Differences

This shows you the differences between two versions of the page.

Link to this comparison view

openjpa [2015/05/13 15:48]
openjpa [2021/04/05 11:23] (current)
Line 1: Line 1:
 +====== 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 (''FetchType.EAGER'')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}}