EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
for (int i = 0; i < MAGAZINE_PUBLISHER_NAME_PAIRS.length; i++) {
String magName = MAGAZINE_PUBLISHER_NAME_PAIRS[i][0];
String pubName = MAGAZINE_PUBLISHER_NAME_PAIRS[i][1];
Magazine mag = new Magazine();
mag.setName(magName);
if (pubName != null) {
Publisher pub = new Publisher();
pub.setName(pubName);
mag.setPublisher(pub);
try {
DateFormat df = new SimpleDateFormat ("yyyy-MM-dd");
Date date = df.parse("2001-01-01");
mag.setDatePublished(date);
} catch (ParseException e) {
mag.setDatePublished(null);
}
mag.setTsPublished(new Timestamp(System.currentTimeMillis() - 100000));
em.persist(pub);
}
em.persist(mag);
}