Example #1
0
 public Employee4 persistEmployee4(EntityManager em, int id) {
   Employee4 p = new Employee4();
   p.setAge(id);
   for (int i = 0; i < numDependentsPerEmployee; i++) {
     Dependent4 c = persistDependent4(em, dId4++, p);
     p.addChild(c);
   }
   em.persist(p);
   return p;
 }
Example #2
0
 public Employee4 mergeEmployee4(EntityManager em, int id) {
   Employee4 e = new Employee4();
   e.setAge(id);
   e = em.merge(e);
   for (int i = 0; i < numDependentsPerEmployee; i++) {
     Dependent4 d = new Dependent4();
     d.setId(dId4++);
     d.setParent(e);
     // do not need to merge d, as Employee is cascade.All
     d = em.merge(d);
     e.addChild(d);
   }
   return e;
 }
Example #3
0
  public static void main(String[] args) {
    // fill the staff array with three Employee4 objects
    Employee4[] staff = new Employee4[3];

    staff[0] = new Employee4("Tom", 40000);
    staff[1] = new Employee4("Dick", 60000);
    staff[2] = new Employee4("Harry", 65000);

    // print out information about all Employee4 objects
    for (Employee4 e : staff) {
      e.setId();
      System.out.println("name=" + e.getName() + ",id=" + e.getId() + ",salary=" + e.getSalary());
    }

    int n = Employee4.getNextId(); // calls static method
    System.out.println("Next available id=" + n);
  }
Example #4
0
 public static void main(String[] args) // unit test
     {
   Employee4 e = new Employee4("Harry", 50000);
   System.out.println(e.getName() + " " + e.getSalary());
 }