/** *Employee Entity Class *Part of employeeDB package *Requires objectdb.jar *@see http://footyntech.wordpress.com/2011/07/23/java-persistence-api-a-quick-intro/ */ package employeeDB; import javax.persistence.*; @Entity publicclass Employee { @Id String name; Double salary; public Employee() { } public Employee (String name, Double Salary) { this.name=name; this.salary=Salary; } publicvoid setSalary(Double Salary) { this.salary=Salary; } publicString toString() { return"Name: "+name+"\nSalary: "+salary ; } } ////////////////////////////// /** *Main Class that implements the Persistence job. Store as seperate file under same package *as that of above class */ package employeeDB; import javax.persistence.*; import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { /** * Displays all Employees in the Database */ private static void displayAll() { em.getTransaction().begin(); TypedQuery e=em.createQuery(displayAllQuery, Employee.class); List employees=e.getResultList(); if(employees.size()>0) { for(Employee temp:employees) { System.out.println(temp); System.out.println(); } System.out.println(employees.size()+" Employee Records Available...!"); } else System.out.println("Database is Empty!"); em.getTransaction().commit(); } /** * Insets an Employee into the Database. */ private static void insert() { System.out.print("Enter the number of Employees to be inserted: "); n=input.nextInt(); em.getTransaction().begin(); for(int i=0;i