ObjectDB ObjectDB

Issue #2447: UPDATE statemen crash when i put the WHERE clause.

Type: Bug ReoprtVersion: 2.8.0_04Priority: HighStatus: ActiveReplies: 1
#1

Hello, i have a problem with a UPDATE statement. When i run the code without WHERE clause the cod is executed, but when i attach the WHERE the program stop there.

The code looks like this.
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();

EntityManager updateEm = emf.createEntityManager();

int lab_points;
for(List<String> linie: linesAsList)
    if(linie.get(1).matches("[a-zA-Z- ]+") && linie.get(2).length()>=2) {

         lab_points = (Integer) em.createQuery("select n.lab_points from Record as n where n.student.nume=:nume and n.student.prenume=:prenume and n.student.grupa=:grupa and n.cours.numeCurs=:curs")
                .setParameter("nume", linie.get(1).split(" ")[0]).setParameter("prenume", linie.get(1).split(" ")[1])
                .setParameter("grupa",linie.get(2)).setParameter("curs","Programare avansata").getSingleResult();

        lab_points = lab_points + Integer.parseInt(linie.get(3).trim());
        System.out.println(lab_points);
        updateEm.getTransaction().begin();
        updateEm.createQuery("update  Record as n set n.lab_points=:points where n.student.nume=:nume").setParameter("nume",linie.get(1).split(" ")[0])
                .setParameter("points",lab_points)
                .executeUpdate();
        updateEm.getTransaction().commit();

        System.out.println(em.createQuery("select n.lab_points from Record as n where n.student.nume=:nume and n.student.prenume=:prenume and n.student.grupa=:grupa and n.cours.numeCurs=:curs")
                .setParameter("nume", linie.get(1).split(" ")[0]).setParameter("prenume", linie.get(1).split(" ")[1])
                .setParameter("grupa", linie.get(2)).setParameter("curs", "Programare avansata").getSingleResult());

    }

if (updateEm.getTransaction().isActive())
    updateEm.getTransaction().rollback();
updateEm.close();

if (em.getTransaction().isActive())
    em.getTransaction().rollback();
em.close();
edit
delete
#2

Apparently this update query is not supported, but a better error message is required.

If you can post the full stack trace of the exception it could help in investigating this further.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.