private Course createSecondCourse()
{
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
// Create Second Course
Course course = new Course("CS364");
course.setId(2L);
tx.begin();
em.persist(course);
tx.commit();
// Create 2 Sections, 2 Students per Section, and 2 Instructors
Student student1 = createPersistedStudent(7L, "John", "Doe", "C11John.Doe",
new Integer(2011));
Student student2 = createPersistedStudent(8L, "Mary", "Johnson",
"C11Mary.Johnson", new Integer(2011));
Student student3 = createPersistedStudent(3L, "Bob", "Reimer",
"C13Robert.Reimer", new Integer(2013));
Student student4 = createPersistedStudent(4L, "Andrew", "Callow",
"C13Andrew.Callow", new Integer(2013));
Student student5 = createPersistedStudent(9L, "Kerry", "Beevers",
"C11Kerry.Beevers", new Integer(2011));
Instructor instructor1 = createPersistedInstructor(5L, "David", "Roberts",
"David.Roberts");
Section section1 = new Section("T5A");
section1.setId(new Long(3L));
Section section2 = new Section("T6A");
section2.setId(new Long(4L));
section1.setCourse(course);
section2.setCourse(course);
// Set the Instructors for Sections 1 & 2
section1.setInstructor(instructor1);
section2.setInstructor(instructor1);
// Add Instructors to Course
course.addInstructor(instructor1);
// Add Students 1 & 2 to Section 1
section1.addStudent(student1);
student1.addSection(section1);
section1.addStudent(student2);
student2.addSection(section1);
course.addSection(section1);
course.addSection(section2);
// Add Students 3 & 4 to Section 2
section2.addStudent(student3);
student3.addSection(section2);
section2.addStudent(student4);
student4.addSection(section2);
section2.addStudent(student5);
student5.addSection(section2);
tx.begin();
em.persist(section1);
em.persist(section2);
em.merge(instructor1);
em.merge(student1);
em.merge(student2);
em.merge(student3);
em.merge(student4);
em.merge(student5);
em.merge(course);
tx.commit();
LOGGER.info("Saved Course (" + course + ") to database with " +
course.getSections().size() + " sections and " +
course.getInstructors().size() + " instructors");
em.close();
return course;
}