blob: 16844b95c64caeed7cd6847bae0c957978d257d8 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>3.&nbsp;Managed Interfaces</title><link rel="stylesheet" href="css/docbook.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.72.0"><link rel="start" href="manual.html" title="Apache OpenJPA 1.2 User's Guide"><link rel="up" href="ref_guide_pc.html" title="Chapter&nbsp;5.&nbsp; Persistent Classes"><link rel="prev" href="ref_guide_pc_enhance.html" title="2.&nbsp; Enhancement"><link rel="next" href="ref_guide_pc_oid.html" title="4.&nbsp; 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.&nbsp;Managed Interfaces</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ref_guide_pc_enhance.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;5.&nbsp;
Persistent Classes
</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ref_guide_pc_oid.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ref_guide_pc_interfaces"></a>3.&nbsp;Managed Interfaces</h2></div></div></div><a class="indexterm" name="d0e22401"></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>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="ref_guide_pc.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ref_guide_pc_oid.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2.&nbsp;
Enhancement
&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;4.&nbsp;
Object Identity
</td></tr></table></div></body></html>