I have put it into a simple class, what am I missing?
public class testObjectDB {
public testObjectDB() {
}
public static void main(String[] args) {
EntityManagerFactory emf = null;
EntityManager em = null;
try {
emf = Persistence.createEntityManagerFactory("objectdb:$objectdb/db/test.tmp;drop");
em = emf.createEntityManager();
em.getTransaction().begin();
Supplier sup = new Supplier();
sup.setDblCost(0);
sup.setStrSupName("ACER");
sup.setStrSupNumber("NX.VDSAA.004");
List<Supplier> lstSup = new ArrayList<>();
lstSup.add(sup);
Supplier sup2 = new Supplier();
sup2.setDblCost(847.21);
sup2.setStrSupName("SYNNEX");
sup2.setStrSupNumber("5785483");
lstSup.add(sup2);
Category cat = new Category("Computer");
List<Category> lstCat = new ArrayList<>();
lstCat.add(cat);
ItemDB item = new ItemDB("ACER", "191114017524", 0.0, 1.0, 1044.95, 0.0, "", "NX.VDSAA.004", "ACER", "ACETMP259M5572",
"Travel Mate P259-M-5572 15.6\" WIN 7",
"NX.VDSAA.004", lstSup, lstCat);
lstSup.clear();
sup = new Supplier();
sup.setDblCost(0);
sup.setStrSupName("ACER");
sup.setStrSupNumber("NH.Q1YAA.001");
lstSup.add(sup);
sup2.setDblCost(2211.47);
sup2.setStrSupName("SYNNEX");
sup2.setStrSupNumber("5759175");
lstSup.add(sup2);
ItemDB item2 = new ItemDB("ACER", "191114036754", 0.0, 1.0, 2763.95, 2211.47, "", "5759175", "SYNNEX", "",
"G9-593-73N6 15.6 FHD W10 Ci7 700HQ BLK", "Computer", lstSup, lstCat);
em.persist(item);
//System.out.println("added item to database " + item.toString());
em.persist(item2);
//System.out.println("added item to database " + item2.toString());
em.getTransaction().commit();
TypedQuery<ItemDB> tqItems = em.createQuery("SELECT i FROM com.model.ItemDB i LEFT JOIN i.lstSupplier s WHERE s.strSupNumber LIKE '%5785483%'" , ItemDB.class);
List<ItemDB> lstItems = tqItems.getResultList();
if(lstItems.isEmpty()){
System.out.println("Could not find the item with both hands");
}
lstItems.forEach(itemed->{
System.out.println("we found an item " + itemed.toString());
});
} catch (Exception e) {
System.out.println("we have an exception adding items" + e.getLocalizedMessage());
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if (em.isOpen()) {
em.close();
}
}
}
}