3. Managed Interfaces
Prev | Chapter 5. Persistent Classes | Next

## 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.

    @ManagedInterface
    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");
    em.getTransaction().begin();
    em.persist(person);
    em.getTransaction().commit();

Prev | Up | Next
2. Enhancement | Home | 4. Object Identity