Home » Support » Issue Tracking » NPE at com.objectdb.jpa.JpaQuery.getResultList

NPE at com.objectdb.jpa.JpaQuery.getResultList

Type: BugVersion: 2.2.7Priority: NormalStatus: ClosedReplies: 3
#1

This is very similar to issue #51  raised by kaosko .   So perhaps I should have added it there.  Anyway, here it is....

 

[ObjectDB 2.2.7_03] Unexpected exception (Error 990)
  Generated by Java HotSpot(TM) 64-Bit Server VM 1.6.0_25 (on Linux 2.6.16.60-0.69.1-smp).
Please report this error on http://www.objectdb.com/database/issue/new
com.objectdb.o.InternalException: java.lang.NullPointerException: null
java.lang.NullPointerException
        at com.objectdb.o.OBC.aY(OBC.java:1300)
        at com.objectdb.o.QRR.b(QRR.java:197)
        at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:618)
        at ie.longpat.jpa.entity.control.MomentPayloadController.findMomentPayloadEntities(MomentPayloadController.java:163)
    public List<MomentPayload> findMomentPayloadEntities() {
        return findMomentPayloadEntities(true, -1, -1);
    }

    public List<MomentPayload> findMomentPayloadEntities(int maxResults, int firstResult) {
        return findMomentPayloadEntities(false, maxResults, firstResult);
    }

    private List<MomentPayload> findMomentPayloadEntities(boolean all, int maxResults, int firstResult) {
        EntityManager em = getEntityManager();
        try {
            CriteriaBuilder cb = em.getCriteriaBuilder();
            CriteriaQuery query = cb.createQuery();
            Root<MomentPayload> fromMomentPayload  = query.from(MomentPayload.class);
            query.select(fromMomentPayload);
            query.orderBy(cb.desc(fromMomentPayload.get("dateTime")));
            Query q = em.createQuery(query);
            if (!all) {
                q.setMaxResults(maxResults);
                q.setFirstResult(firstResult);
            }
            return q.getResultList();
        } finally {
            em.close();
        }
    }
#2

It seems as a separate issue. Maybe related to pessimistic locking.

Can you provide a test case? The following program throws no exception.

import java.util.*;

import javax.persistence.*;
import javax.persistence.criteria.*;

public class T366 {
   
    public static void main(String[] args) {
        new T366().findMomentPayloadEntities();
    }

    public List<MomentPayload> findMomentPayloadEntities() {
        return findMomentPayloadEntities(true, -1, -1);
    }

    public List<MomentPayload> findMomentPayloadEntities(
            int maxResults, int firstResult) {
        return findMomentPayloadEntities(false, maxResults, firstResult);
    }

    private List<MomentPayload> findMomentPayloadEntities(
        boolean all, int maxResults, int firstResult) {
       
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory("$objectdb/db/test.odb");
        EntityManager em = emf.createEntityManager();
       
        try {
            CriteriaBuilder cb = em.getCriteriaBuilder();
            CriteriaQuery query = cb.createQuery();
            Root<MomentPayload> fromMomentPayload  = query.from(MomentPayload.class);
            query.select(fromMomentPayload);
            query.orderBy(cb.desc(fromMomentPayload.get("dateTime")));
            Query q = em.createQuery(query);
            if (!all) {
                q.setMaxResults(maxResults);
                q.setFirstResult(firstResult);
            }
            return q.getResultList();
        }
        finally {
            em.close();
            emf.close();
        }
    }

    @Entity
    public static final class MomentPayload {
        java.sql.Timestamp dateTime;
    }
}

 

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

Unfortunately, I have not been able to reproduce this exception. (which is good, I suppose!)

Around the time it occurred, there was a change made to the entity persistent fields and its relationship. I think perhaps the old instances were still in the db at the time.

Anyway, I will keep a look out for its recurrence.

 

#4

Maybe the server was still running. Schema changes requires server restart.

I am closing this issue - reopen it if you have more info.

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

Post Reply

To post a reply and/or subscribe to update notifications - please login