public static void main(String[] args) { EntityManagerFactory emf = Persistence.createEntityManagerFactory("nwind-pu"); EntityManager em = emf.createEntityManager(); int id = 2; Supplier supp = em.find(Supplier.class, id); System.out.println("Supplier Id:" + supp.getSupplierId()); System.out.println("Supplier Name:" + supp.getCompanyName()); System.out.println("Products in this category are"); for (Product p : supp.getProducts()) { System.out.println("\t" + p.getProductName()); } }
public static void main(String[] args) throws Exception { Product p1 = new Product(); p1.setProductId(1); p1.setProductName("Chai"); Product p2 = new Product(); p2.setProductId(2); p2.setProductName("Chang"); ProductDao dao = new FileProductDao(); dao.addProduct(p1); dao.addProduct(p2); System.out.println("Done."); }