/
samples_guide.xml
177 lines (174 loc) · 6.69 KB
/
samples_guide.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2006 The Apache Software Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<chapter id="samples_guide">
<title>
OpenJPA Sample Code
</title>
<para>
The OpenJPA distribution comes with a number of examples that illustrate the
usage of various features.
</para>
<!--
This is information on the sample application. It will be included
in the documentation (see doc/openjpa/samples-guide.xml). It will also
automatically be converted into a README.txt file in this directory
in the "release.openjpa.releasedocs" build target phase of the release.
-->
<section id="samples_guide_interop">
<title>
JDO - JPA Persistence Interoperability
</title>
<para>
This sample demonstrates how to combine JDO and JPA in a single application. The
<filename>MachineMain.java</filename> program uses both <classname>
EntityManager</classname>s and <classname>PersistenceManager</classname>s in a
single transaction including persist, delete and query operations.
</para>
<para>
The sample includes both annotated persistent classes as well as JDOR metadata
information. The application can switch to either system simply by changing the
bootstrap mechanism. Depending on which configuration system you use, OpenJPA
will read the corresponding metadata format. You can override some or all of
this behavior using OpenJPA's configuration options, such as
<link linkend="openjpa.MetaDataFactory">openjpa.MetaDataFactory</link>.
</para>
<para>
To use this sample, you should ensure that either a <filename>jdo.properties
</filename> or <filename>persistence.xml</filename> are in the <filename>
META-INF</filename> directory in your <envar>CLASSPATH</envar>. The rest of the
files for this sample are located in the <filename>samples/mixed</filename>
directory of the OpenJPA installation. This tutorial requires JDK 5. To run this
tutorial:
</para>
<itemizedlist>
<listitem>
<para>
Ensure that your environment is set properly as described in the README and that
your current path is in the mixed sample directory.
</para>
</listitem>
<listitem>
<para>
You may want to edit <literal>ConnectionURL</literal> to point to an absolute
URL (e.g. <filename>C:/openjpa/mixed-sample-db</filename>) if using a
file-based database like <literal>HSQL</literal>.
</para>
</listitem>
<listitem>
<para>
Include the list of persistent classes in your configuration file. For JPA, you
will want to add the following lines to <filename>persistence.xml</filename>
before the <literal><property></literal> lines:
</para>
<programlisting>
<class>samples.mixed.Machine</class>
<class>samples.mixed.Crane</class>
<class>samples.mixed.Bulldozer</class>
<class>samples.mixed.Operator</class>
</programlisting>
<para>
If you are using JDO, point the metadata factory at the <filename>.jdo
</filename> resource containing your persistent classes:
</para>
<programlisting>
openjpa.MetaDataFactory: Resources=samples/mixed/package.jdo
</programlisting>
</listitem>
<listitem>
<para>
Compile the classes:
</para>
<para>
<userinput>javac *.java</userinput>
</para>
</listitem>
<listitem>
<para>
You should then proceed to pass in the configuration file you are using to the
enhancer:
</para>
<para>
<userinput>java org.apache.openjpa.enhance.PCEnhancer -p persistence.xml Machine.java Crane.java Bulldozer.java
Operator.java</userinput>
</para>
</listitem>
<listitem>
<para>
Similarly, you should pass in the same argument to <literal>org.apache.openjpa.jdbc.meta.MappingTool</literal>:
</para>
<para>
<userinput>java org.apache.openjpa.jdbc.meta.MappingTool -p persistence.xml -a buildSchema Machine.java
Crane.java Bulldozer.java Operator.java</userinput>
</para>
<para>
or
</para>
<para>
<userinput>java org.apache.openjpa.jdbc.meta.MappingTool -p jdo.properties -a buildSchema Machine.java Crane.java
Bulldozer.java Operator.java</userinput>
</para>
</listitem>
<listitem>
<para>
You can now run the sample application. The first argument is which operation
you want the program to run. The second argument tells the application which
bootstrap system to use:
</para>
<para>
<userinput>java samples.mixed.MachineMain <create | delete> <jdo |
jpa></userinput>
</para>
</listitem>
</itemizedlist>
</section>
<section id="samples_guide_jpadiv">
<title>
JPA
</title>
<!--
This is information on the sample application. It will be included
in the documentation (see doc/openjpa/samples-guide.xml). It will also
automatically be converted into a README.txt file in this directory
in the "release.jdo.releasedocs" build target phase of the release.
-->
<section id="samples_guide_model_humres_jpa">
<title>
Sample Human Resources Model
</title>
<para>
The files for this sample are located in the <filename>
samples/persistence/models/humres</filename> directory of the OpenJPA
installation. This sample demonstrates the mapping of an example "Human
Resources" schema. The following concepts are illustrated in this sample:
</para>
<itemizedlist>
<listitem>
<para>
Value Mappings
</para>
</listitem>
<listitem>
<para>
One to One Mappings
</para>
</listitem>
<listitem>
<para>
One to Many Mappings (with and without inverses)
</para>
</listitem>
</itemizedlist>
</section>
</section>
</chapter>