OpenJPA Entity Enhancement in OSGI container


In this example we will see how to enhance the JPA entities before usage in OSGi container.

Let’s assume we got an entity called Person.


import javax.persistence.Entity;
import javax.persistence.Id;

public class Person implements Serializable {
    private static final long serialVersionUID = 1L;

    private long id;

    private String name;

    public long getId() {
        return id;

    public void setId(long id) { = id;

    public String getName() {
        return name;

    public void setName(String name) { = name;


Maven Dependencies



Maven Plugin

     <path id="enhance.path.ref">
      <fileset dir="${}">
       <include name="Person.class" />
     <pathconvert property="enhance.files" refid="enhance.path.ref"
         pathsep=" " />
     <java classname="org.apache.openjpa.enhance.PCEnhancer">
      <arg line="-p persistence.xml" />
      <arg line="${enhance.files}" />
       <path refid="maven.dependency.classpath" />
       <path refid="maven.compile.classpath" />