ObjectDB ObjectDB

Issue #2828: Unexpected exception when execute query without enhanced entities

Type: Bug ReoprtVersion: 2.8.7Priority: NormalStatus: ActiveReplies: 10
#1

ObjectDB 2.8.7.b08


Our entities are not enhanced and we execute a query "select max(uid) from ModelElementImpl".

In the objectdb.conf the reflection is set to error.

<entities>
        ...
        <enhancement agent="false" reflection="error" />

 

We got following exception after execution of the query:

Caused by: com.objectdb.o.UserException: Unexpected query token 'uid'
        at com.objectdb.o.TKN.w(TKN.java:802)
        at com.objectdb.o.QNF.h(QNF.java:446)
        at com.objectdb.o.QNF.v(QNF.java:171)
        at com.objectdb.o.QNF.a(QNF.java:1233)
        at com.objectdb.o.QNF.v(QNF.java:267)
        at com.objectdb.o.QRC.f(QRC.java:643)
        at com.objectdb.o.QRC.g(QRC.java:615)
        at com.objectdb.o.QRC.m(QRC.java:560)
        at com.objectdb.o.QRC.t(QRC.java:241)
        at com.objectdb.o.QRC.j(QRC.java:190)
        at com.objectdb.o.QRM.ZO(QRM.java:273)
        at com.objectdb.o.MST.ZO(MST.java:1026)
        at com.objectdb.o.WRA.ZO(WRA.java:313)
        at com.objectdb.o.WSM.ZO(WSM.java:117)
        at com.objectdb.o.QRR.k(QRR.java:260)
        at com.objectdb.o.QRR.i(QRR.java:154)
        at com.objectdb.jpa.JpaQuery.getSingleResult(JpaQuery.java:760)


I would expect an exception with a message like "the entities are not enhanced ..." instead of the UserException: Unexpected query token 'uid'.

If the entities are enhanced then the query works without exception.

edit
delete
#2

Is it possible that these are two separate issues?

The reflection error is triggered only when the class is used against ObjectDB, e.g. to create the objects that the query returns.

Here it seems that there is another (earlier) error in the query compilation, so the non-enhanced class is not even used, as queries are compiled against the existing schema in the database.

Maybe the two issues are related, i.e. uid is unknown due to partial enhancement, broken inheritance as a result of partial enhancement or maybe a recent schema change.

ObjectDB Support
edit
delete
#3

Actually I don't see two issues here.

The query "select m from ModelElementImpl m" works with enhanced entities and reflection="error".

But without enhanced entities I get the exception:
com.objectdb.o.InternalException: Unexpected internal exception
    at com.objectdb.o.JPE.e(JPE.java:170) ~[na:na]
    at com.objectdb.o.ERR.h(ERR.java:66) ~[na:na]
    at com.objectdb.o.OBC.onObjectDBError(OBC.java:1591) ~[na:na]
    at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:738) ~[na:na]
edit
delete
#4

The exception in #3 above is different from the exception in #1 above and the query is also different.

So leaving #1 aside (as it does look as a different issue, even if somehow related), #3 indeed demonstrates an internal exception where a better error message is expected. We will investigate it. Thank you for this report.

ObjectDB Support
edit
delete
#5

Version 2.8.8_03 should throw an exception with the correct error message in this case.

If the exception in #3 above is fixed, you may try now also #1 and report whether it is also solved.

ObjectDB Support
edit
delete
#6

With version 2.8.8_03 we get another exception stack trace when the entities are not enhanced.

 

com.objectdb.o._PersistenceException: Unexpected query token 'uid'
    at com.objectdb.o._PersistenceException.a(_PersistenceException.java:47) ~[na:na]
    at com.objectdb.o.JPE.d(JPE.java:147) ~[na:na]
    at com.objectdb.o.ERR.h(ERR.java:56) ~[na:na]
    at com.objectdb.o.OBC.onObjectDBError(OBC.java:1591) ~[na:na]
    at com.objectdb.jpa.JpaQuery.getSingleResult(JpaQuery.java:769) ~[na:na]
    ...
Caused by: com.objectdb.o.UserException: Unexpected query token 'uid'
    at com.objectdb.o.MSG.a(MSG.java:64) ~[na:na]
    at com.objectdb.o.TKN.w(TKN.java:802) ~[na:na]
    at com.objectdb.o.QNF.h(QNF.java:446) ~[na:na]
    at com.objectdb.o.QNF.v(QNF.java:171) ~[na:na]
    at com.objectdb.o.QNF.a(QNF.java:1233) ~[na:na]
    at com.objectdb.o.QNF.v(QNF.java:267) ~[na:na]
    at com.objectdb.o.QRC.f(QRC.java:643) ~[na:na]
    at com.objectdb.o.QRC.g(QRC.java:615) ~[na:na]
    at com.objectdb.o.QRC.m(QRC.java:560) ~[na:na]
    at com.objectdb.o.QRC.t(QRC.java:241) ~[na:na]
    at com.objectdb.o.QRC.j(QRC.java:190) ~[na:na]
    at com.objectdb.o.QRM.Y3(QRM.java:273) ~[na:na]
    at com.objectdb.o.MST.Y3(MST.java:1026) ~[na:na]
    at com.objectdb.o.WRA.Y3(WRA.java:313) ~[na:na]
    at com.objectdb.o.WSM.Y3(WSM.java:117) ~[na:na]
    at com.objectdb.o.QRR.k(QRR.java:260) ~[na:na]
    at com.objectdb.o.QRR.i(QRR.java:154) ~[na:na]
    at com.objectdb.jpa.JpaQuery.getSingleResult(JpaQuery.java:760) ~[na:na]
    ... 28 common frames omitted
edit
delete
#7

The exception in #6 is similar to #1, so apparently version 2.8.8_03 solves #3 but not #1 / #6.

Following is an attempt to reproduce error #1 / #6:

package com.objectdb.test.bug.forum;

import java.util.*;

import javax.persistence.*;

public class F2828 {
    public static void main(String[] args) {
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory("objectdb:F2828.tmp");
        // store(emf);
        retrieve(emf);
        emf.close();
    }

    private static void store(EntityManagerFactory emf) {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        em.persist(new MyEntity());
        em.persist(new MyEntity());
        em.getTransaction().commit();
        em.close();
    }

    private static void retrieve(EntityManagerFactory emf) {
        EntityManager em = emf.createEntityManager();
        List resultList = em.createQuery(
            "select max(uid) from MyEntity").getResultList();
        System.out.println(resultList.size());
        em.close();
    }

    @Entity
    public static class MyEntity {
        @Id @GeneratedValue
        int uid;
    }
}

The output was the expected error message:

Exception in thread "main" [ObjectDB 2.x] javax.persistence.PersistenceException
Type com.objectdb.test.bug.forum.F2828$MyEntity is not enhanced (enhance the type or enable reflection) (error 304)
    at com.objectdb.jpa.EMF.createEntityManager(EMF.java:152)
    at com.objectdb.test.bug.forum.F2828.retrieve(F2828.java:26)
    at com.objectdb.test.bug.forum.F2828.main(F2828.java:12)

In order to proceed with the investigation of this issue we will need a minimal test case that reproduces this error, if possible based on the code above.

ObjectDB Support
edit
delete
#8

If I try to persist a not enhanced DMO with reflection="error" then I get the exception:

[ObjectDB 2.8.8_03] Unexpected exception (Error 990)
  Generated by OpenJDK 64-Bit Server VM 11.0.8 (on Windows 10 10.0).
Please report this error on https://www.objectdb.com/issue
com.objectdb.o.InternalException: java.lang.NullPointerException: null
java.lang.NullPointerException
    at com.objectdb.o.OBM.aQ(OBM.java:427)
    at com.objectdb.o.OBM.aQ(OBM.java:301)
    at com.objectdb.jpa.EMImpl.persist(EMImpl.java:421)

 

With reflection="warning" the code works.

edit
delete
#9

Your reports show that version 2.8.8_03 does not fix this issue entirely. It does solves the issue with the small test case in #7 above (which follows the stack trace in #3). However, to be able to understand where it still fails more information is needed. Could you adjust the test case in #7 to the situation in #8 and demonstrate the exception with such a small test case?

ObjectDB Support
edit
delete
#10

I checked the ObjectDB versions.

The issue was introduced with version objectdb-2.8.4_02 or objectdb-2.8.4_01.

The version objectdb-2.8.4 works as expected and shows the correct error message.

Maybe you have an idea.

edit
delete
#11

Thank you for the tip but after scanning all the differences between versions 2.8.4 and 2.8.5 it is still unclear what could cause this regression.

The stack trace in #8 above is partial, could you please check if extended stack trace is available in the log file?

If you could alter the test case in #7 above in a way that it would produce the error it would probably be very helpful.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.