public static void main(String[] args) {

		String unitName = args.length == 0 ?  "jpademo" : args[0];

		JPAQuery program = new JPAQuery();

		// Do i/o initializations before JPA to fail fast
		program.init();

		System.out.println("JPAQuery.main() -- starting JPA " + unitName);

		// This would be done for you
		// were you running in an EE App Server
		EntityManager entityManager = null;
		try {
			entityMgrFactory = 
			Persistence.createEntityManagerFactory(unitName);
			System.out.println("Created EntityManagerFactory");
			entityManager = entityMgrFactory.createEntityManager();

			// Delegate
			program.run(entityManager);

		} catch (Exception e) {
			System.out.println("JPA failure: " + e);
			e.printStackTrace();
			return;
		} finally {	
			if (entityManager != null)
				entityManager.close();
			if (entityMgrFactory != null)
				entityMgrFactory.close();
		}
	}