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.

public class ContactPerson {

        @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval=true)
        private List<Phone> phones;


public class ContactPersonService {

	public ContactPerson update(ContactPerson contactPerson) {
		if (contactPerson.getPhones() == null) {
			contactPerson.setPhones(new LinkedList());

                return em.merge(contactPerson);