...
This page provides samples for OpenJPA. For further information, the documentation provides comprehensive documentation on all aspects of configuring and using OpenJPA. A template is provided to describe how to build, deploy and run the samples. The existing samples will be reformatted to fit the template. If you are
creating new samples, please adhere to the template.
For more information on using OpenJPA within a Java EE application server, please see the Container Integration page for more details.
- Open JPA Basic Sample and tutorial
- OpenTrader - a transactional web application featuring how to integrate Google Web Toolkit and OpenJPA
- OpenBooks - a end-to-end example featuring new JPA 2.0 features in JSE and JEE environments
- Using Criteria API in DayTrader
- Bean Validation Primer - A simple example which demonstrates the use Bean Validation with OpenJPA
OpenJPA ANT Examples
These are some short (5 minutes) quick start guides for OpenJPA using the example examples provided with the distribution. Most OpenJPA releases require Java SE 5, but see Build and Runtime Dependencies for more details.
...
- Download the OpenJPA binary release from the downloads page and unpack it by double-clicking it.
- Launch Eclipse (this sample was tested with Eclipse 3.2.1, but any recent version should work).
- Select the File menu, traverse to the New sub-menu, and select Project.
- On the Select a wizard page, select Java Project from Existing Ant Buildfile, then click the Next button.
- Hit the Browse button next to the Ant Buildfile field, and navigate to the unpacked OpenJPA zip file on the desktop, then traverse through examples, then hellojpa, and select the build.xml file and hit the Open button.
- Hit the Finish button on the wizard.
- A new project will open, containing the OpenJPA jar and all its dependencies.
- On the Package Explorer, expand the top-level folder, then the examples folder, then hellojpa.
- Select the build.xml file in the hellojpa folder (note that there is also a build.xml file in the parent folder, which should not be selected). Right-click the build.xml file, and select the Run As sub-menu, then select Ant Build.
- The database will be initialized (using the stand-alone Derby database, which is included with the OpenJPA distribution) and the Main.java class will be run. In the Console, you should see the text Hello Persistence!.
- Congratulations! You have run your first sample program using OpenJPA. Examine the Main.java example program, as well as the Message.java entity class, play with them by adding fields and working on new persistence operations. Have fun!
Getting Started with the Console
- Ensure that you have Apache Ant installed (this sample was tested with ant 1.6.5, but any recent version should work).
- Download the OpenJPA binary release from the downloads page and unpack it by double-clicking it.
- Launch a console, such as cmd.exe on Windows, Terminal.app on Mac, or xterm on UNIX.
- Change directories to the Desktop, then cd to the unpacked OpenJPA folder.
- cd to the examples subdirectory, then to the hellojpa subdirectory.
- Run ant, which will compile the classes and run the sample application. At the end of the build, you should see the text Hello Persistence!.
- Congratulations! You have run your first sample program using OpenJPA. Examine the Main.java example program, as well as the Message.java entity class, play with them by adding fields and working on new persistence operations. Have fun!
Getting Started with Netbeans
- Download the OpenJPA binary release from the downloads page and unpack it by double-clicking it.
- Launch Netbeans (this sample was tested with Netbeans 5.5, but any recent version should work).
- Select the File menu and select New Project.
- On the New Project page, select Category:General Projects:Java Project with Existing Ant Script, then click the Next button.
- Press the Browse button next to the Location field, and navigate to the unpacked OpenJPA directory
- Press the Browse button next to the Build Script field, and navigate to the unpacked OpenJPA directory through examples, then hellojpa, and select the build.xml file and press the Open button.
- Type a name for the project, press Set as Main Project and press the Next button on the wizard.
- Press Next to accept the Build and Run Actions.
- On the Source Package Folders page, press Add Folder, select the examples folder, and press Next.
- On the Java Sources Classpath page, press Add JAR/Folder and select the openjpa-x.x.x/lib/geronimo-jpa_3.0_spec-1.0.jar which contains the JPA API classes which is used to compile against.
- Press Finish
- A new project will open, containing the OpenJPA jar and the examples source files.
- On the Package Explorer, expand the top-level folder, then the examples folder, then hellojpa.
- Navigate to the build.xml file in the hellojpa folder (note that there is also a build.xml file in the parent folder, which should not be used). Right-click the build.xml file, and select the Run Target sub-menu, then select run.
- The database will be initialized (using the stand-alone Derby database, which is included with the OpenJPA distribution) and the Main.java class will be run. In the Console, you should see the text Hello Persistence!.
- Congratulations! You have run your first sample program using OpenJPA. Examine the Main.java example program, as well as the Message.java entity class, play with them by adding fields and working on new persistence operations. Have fun!
Other Examples
Apache TomEE Examples
All the above examples are standalone projects, contain unit tests and working maven pom.xml files. Examples are run with every build and release of TomEE.
...
Apache Geronimo v2.1 Samples
...