3. Managed Interfaces

OpenJPA's managed interface feature allows you to define your object model entirely in terms of interfaces, instead of concrete classes. To use this feature, you must annotate your managed interfaces with the ManagedInterface annotation, and use the OpenJPAEntityManager.createInstance(Class) method to create new records. Note that createInstance() returns unmanaged instances; you must pass them to EntityManager.persist() to store them in the database.

public interface PersonIface {
    @Id @GeneratedValue
    int getId();
    void setId(int id);

    // implicitly persistent per JPA property rules
    String getName();
    void setName(String name);
OpenJPAEntityManager em = ...;
PersonIface person = em.createInstance(PersonIface.class);
person.setName("Homer Simpson");