Introduction
I have been developing Java applications for a long time and the major difficulty was the coding part related to database manipulations. Recently I shifted to use Object-Relational Mapping through JPA. I have used TopLink, EclipseLink, and Hibernate. Although I could achieve the functionally I want with ease, the output was slower when compared to normal method of database connection with JDBC. Then I used some Object databases like neoDatis. They were quite faster, yet I was reluctant to proceed as most of them had their own standards and did not comply to JPA. Finally I found the ObjectDB, an Object database for Java which completely supports JPA.
This article demonstrates how to create a simple JAVA Standard application in NetBeans using ObjectDB and JPA. The demonstrated application uses JPA to store and retrieve objects of two entity classes from an Embedded ObjectDB. It will demonstrate the capabilities of ObjectDB and JPA, which include persisting objects, removing saved objects and retrieving persisted objects. For this tutorial, besides the Java JDK and the NetBeans IDE,you only need to download
and extract the ObjectDB distribution zip file.The distribution zip contains everything necessary without any external dependency.
This tutorial consists of the following steps
- Step 1: Create an ObjectDB Enabled Java SE Project
- Step 2: Define a JPA Entity Classes
- Step 3: Add a Main Class
- Step 4: Design a Graphical User Interface
- Step 5: Code user-defined Methods
- Step 6: Code Events of Controls
- Step 7: Run the program
Step 1: Create an ObjectDB Enabled Project
We start by creating a new NetBeans Project.
From the menu, select File > New to get the [New Project] dialog box
Select Java from Categories and
Java Application from Projects and click Next
Choose a Project Name (e.g City
Set the name of the Main class to main.Main – This will create a package named main and a Java Class named Main with the public static void main(String[] args){}
Click Finish to create the project.
Then ObjectDB/JPA support has to be added to the project
Download the ObjectDB installation files from the download page. The downloaded file, objectdb-(version).zip file has to be extracted to a folder like D:\Program Files\ObjectDB.
Find the project in Project window.If project window is not visible, press ctrl + 1 to get the project window. Right click on the project to get the popup menu and select the Properties to get the [Project Properties] window.
Click on Libraries under categories of the Project Properties Window. No libraries are listed at the moment under Compile tab.
Click on Add Jar/Folderand locate the objectdb.jar file inside the bin folder of ObjectDB extracted directory.
This will add the objectdb.jar file to the libraries and now the project is JPA/ObjectDB enabled.







February 19, 2011
Hibernate, JPA