1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>Persistent Objects</title> 7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.62.4" /> 9 <link rel="home" href="index.html" title="Getting Started with Berkeley DB" /> 10 <link rel="up" href="persist_first.html" title="Chapter��3.��Direct Persistence Layer First Steps" /> 11 <link rel="previous" href="persist_first.html" title="Chapter��3.��Direct Persistence Layer First Steps" /> 12 <link rel="next" href="saveret.html" title="Saving a Retrieving Data" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Persistent Objects</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="persist_first.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��3.��Direct Persistence Layer First Steps</th> 23 <td width="20%" align="right">��<a accesskey="n" href="saveret.html">Next</a></td> 24 </tr> 25 </table> 26 <hr /> 27 </div> 28 <div class="sect1" lang="en" xml:lang="en"> 29 <div class="titlepage"> 30 <div> 31 <div> 32 <h2 class="title" style="clear: both"><a id="persistobject"></a>Persistent Objects</h2> 33 </div> 34 </div> 35 <div></div> 36 </div> 37 <p> 38 When using the DPL, you store data in the underlying 39 DB databases by making objects 40 <span class="emphasis"><em>persistent</em></span>. You do this using Java 41 annotations that both identify the type of persistent 42 object you are declaring, as well as the primary and 43 secondary indices. 44 </p> 45 <p> 46 The following are the annotations you will use with your 47 DPL persistent classes: 48 </p> 49 <div class="informaltable"> 50 <table border="1" width="80%"> 51 <colgroup> 52 <col /> 53 <col /> 54 </colgroup> 55 <thead> 56 <tr> 57 <th>Annotation</th> 58 <th>Description</th> 59 </tr> 60 </thead> 61 <tbody> 62 <tr> 63 <td>@Entity</td> 64 <td> 65 Declares an entity class; that is, a class with a primary index 66 and optionally one or more indices. 67 </td> 68 </tr> 69 <tr> 70 <td>@Persistent</td> 71 <td> 72 Declares a persistent class; that is, a class used by an entity 73 class. They do not have indices but instead are are stored or 74 retrieved when an entity class makes direct use of them. 75 </td> 76 </tr> 77 <tr> 78 <td>@PrimaryKey</td> 79 <td> 80 Declares a specific data member in an entity class to be the 81 primary key for that object. This annotation must be used one 82 and only one time for every entity class. 83 </td> 84 </tr> 85 <tr> 86 <td>@SecondaryKey</td> 87 <td> 88 Declares a specific data member in an entity class to be a 89 secondary key for that object. This annotation is optional, and 90 can be used multiple times for an entity class. 91 </td> 92 </tr> 93 </tbody> 94 </table> 95 </div> 96 <p> 97 For example, the following is declared to be an entity class: 98 </p> 99 <pre class="programlisting">package persist.gettingStarted; 100 101import com.sleepycat.persist.model.Entity; 102import com.sleepycat.persist.model.PrimaryKey; 103 104@Entity 105public class ExampleEntity { 106 107 private String aPrimaryKey; 108 private String aSecondaryKey; 109 110 // The primary key must be unique in the database. 111 @PrimaryKey 112 private String aPrimaryKey; 113 114 @SecondaryKey(relate=MANY_TO_ONE) 115 private String aSecondaryKey; 116 117 ... 118 119 // The remainder of the class' implementation is purposefully 120 // omitted in the interest of brevity. 121 122 ... 123} </pre> 124 <p> 125 We discuss primary and secondary keys in more detail in <a href="persist_index.html">Working with Indices</a>. 126 </p> 127 </div> 128 <div class="navfooter"> 129 <hr /> 130 <table width="100%" summary="Navigation footer"> 131 <tr> 132 <td width="40%" align="left"><a accesskey="p" href="persist_first.html">Prev</a>��</td> 133 <td width="20%" align="center"> 134 <a accesskey="u" href="persist_first.html">Up</a> 135 </td> 136 <td width="40%" align="right">��<a accesskey="n" href="saveret.html">Next</a></td> 137 </tr> 138 <tr> 139 <td width="40%" align="left" valign="top">Chapter��3.��Direct Persistence Layer First Steps��</td> 140 <td width="20%" align="center"> 141 <a accesskey="h" href="index.html">Home</a> 142 </td> 143 <td width="40%" align="right" valign="top">��Saving a Retrieving Data</td> 144 </tr> 145 </table> 146 </div> 147 </body> 148</html> 149