ObjectDB ObjectDB

Embedded List

#1

Why does this NamedQuery only work sometimes?

@NamedQuery(name = "ItemDB.getPartial", query = "SELECT i FROM com.model.ItemDB i JOIN i.lstSupplier s WHERE s.strSupNumber LIKE ?1")

I use this to access it.

TypedQuery<ItemDB> tqItem = emf.createEntityManager().createNamedQuery("ItemDB.getPart", ItemDB.class).setParameter(1, strSupPart);

strSupPart is the part I am looking for in my Embedded List

edit
delete
#2

Please provide more precise details (what do you mean by "only work sometimes"?), and if possible, also a minimal runnable program in a format as specified in the posting instructions

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
edit
delete
#3

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();
            }
        }
    }
}

 

edit
delete
#4

Could you please provide some more details about the question. On #1 and #3 you provided code. Is it runnable? What is the exact issue?

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
edit
delete
#5

So the code is runnable if you have the 2 files from the first comment, I am trying to get records that have part of the strSupPart field from the Embedded class in the ItemDB class, my code looks right, but it doesn't return any results, what am I doing wrong?

edit
delete
#6

Please try minimizing the code to a minimal runnable class, following the posting instructions format (i.e. minimal classes, minimum fields, minimum functions, etc.). Unfortunately we cannot investigate code that is not minimal.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
edit
delete

Reply

To post on this website please sign in.