| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>3. Managed Interfaces</title><base href="display"><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="manual.html" title="Apache OpenJPA 2.4 User's Guide"><link rel="up" href="ref_guide_pc.html" title="Chapter 5. Persistent Classes"><link rel="prev" href="ref_guide_pc_enhance.html" title="2. Enhancement"><link rel="next" href="ref_guide_pc_oid.html" title="4. Object Identity"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3. Managed Interfaces</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ref_guide_pc_enhance.html">Prev</a> </td><th width="60%" align="center">Chapter 5. |
| Persistent Classes |
| </th><td width="20%" align="right"> <a accesskey="n" href="ref_guide_pc_oid.html">Next</a></td></tr></table><hr></div><div class="section" id="ref_guide_pc_interfaces"><div class="titlepage"><div><div><h2 class="title" style="clear: both">3. Managed Interfaces</h2></div></div></div> |
| |
| <a class="indexterm" name="d5e12301"></a> |
| <p> |
| 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 |
| <code class="classname">ManagedInterface</code> annotation, and use the |
| <code class="literal">OpenJPAEntityManager.createInstance(Class)</code> method to |
| create new records. Note that <code class="literal">createInstance()</code> returns |
| unmanaged instances; you must pass them to |
| <code class="literal">EntityManager.persist()</code> to store them in the database. |
| </p> |
| <pre class="programlisting"> |
| @ManagedInterface |
| public interface PersonIface { |
| @Id @GeneratedValue |
| int getId(); |
| void setId(int id); |
| |
| // implicitly persistent per JPA property rules |
| String getName(); |
| void setName(String name); |
| } |
| </pre> |
| <pre class="programlisting"> |
| OpenJPAEntityManager em = ...; |
| PersonIface person = em.createInstance(PersonIface.class); |
| person.setName("Homer Simpson"); |
| em.getTransaction().begin(); |
| em.persist(person); |
| em.getTransaction().commit(); |
| </pre> |
| </div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ref_guide_pc_enhance.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ref_guide_pc.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ref_guide_pc_oid.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2. |
| Enhancement |
| </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> 4. |
| Object Identity |
| </td></tr></table></div></body></html> |