Home » Support » Forum » TYPE Expression

TYPE Expression

#1

Hi there!

Trying to add a simple type expression with the criteria api like in your sample:

cb.equal(e.type(), cb.literal(Country.class));

results in the error:

Caused by: com.objectdb.o.UserException: Attempt to store an instance of a non persistable type java.lang.Class
at com.objectdb.o.MSG.d(MSG.java:61)
at com.objectdb.o.TYW.writeElement(TYW.java:223)
at com.objectdb.o.QRR.l(QRR.java:424)
at com.objectdb.o.QRR.g(QRR.java:230)
at com.objectdb.o.QRR.b(QRR.java:151)

here's some other a little bit above:

Caused by: com.objectdb.o._PersistenceException: Attempt to store an instance of a non persistable type java.lang.Class
at com.objectdb.o._PersistenceException.b(_PersistenceException.java:45)
at com.objectdb.o.JPE.g(JPE.java:140)
at com.objectdb.o.ERR.f(ERR.java:59)
at com.objectdb.o.OBC.onObjectDBError(OBC.java:1485)
at com.objectdb.jpa.JpaQuery.getSingleResult(JpaQuery.java:702)

when trying to get a result list. leaving it out removes the error, other filters like string equals etc. work just fine?

thanks for any help!

PS: Using ODB 2.3.3

Alex

#2

Hi,

Note, this doesn't seem to work either using simple string query in explorer:

SELECT FROM com.test.MyEntity c WHERE TYPE(c) = com.test.MyEntity

-> causes parsing error

whereas this works as expected:

SELECT FROM com.test.MyEntity  c

Note that my Entity is named "com.test.MyEntity", it is not the complete package path but the exact name of the entity.

Alex

#3

Build 2.3.4_02 includes a partial fix and the following test should work:

package com.objectdb.test.bug.forum;

import java.io.*;
import java.util.*;

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

@Entity
public class T598 {
    public static void main(String[] args) {
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory(
                "objectdb:$objectdb/db/test.tmp;drop");
       
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        em.persist(new A());
        em.persist(new A());
        em.persist(new B());
        em.getTransaction().commit();
        em.close();
       
        em = emf.createEntityManager();
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<Object> cq = cb.createQuery();
        Root<A> e = cq.from(A.class);
        cq.select(e);
        cq.where(cb.equal(e.type(), cb.literal(A.class)));
        System.out.println("Query: " + cq);
        List<Object> resultList = em.createQuery(cq).getResultList();
        System.out.println("Size: " + resultList.size());
        em.close();

        em = emf.createEntityManager();
        Query query = em.createQuery("SELECT From A a WHERE TYPE(a)=:type");
        query.setParameter("type", A.class);
        resultList = query.getResultList();
        System.out.println("Size: " + resultList.size());
        em.close();

        emf.close();
    }
   
    @Entity
    public static class A implements Serializable {
    }

    @Entity
    public static class B {
    }
}

There is still a problem with parsing class literals in query strings, as you reported in #2.

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

hi!

Just upgraded to 2.3.4_02 though with my code I still get this when trying to use TYPE:

Caused by: com.objectdb.o.UserException: Attempt to store an instance of a non persistable type java.lang.Class
at com.objectdb.o.MSG.d(MSG.java:61)
at com.objectdb.o.TYW.writeElement(TYW.java:223)
at com.objectdb.o.QRR.l(QRR.java:424)
at com.objectdb.o.QRR.g(QRR.java:230)
at com.objectdb.o.QRR.b(QRR.java:151)
at com.objectdb.jpa.JpaQuery.getSingleResult(JpaQuery.java:695)

 

any idea???

Alex

#5

Even this simple code causes the same error:

private void applyFilters(Root<T> from, CriteriaQuery<?> query, CriteriaBuilder builder)
{
  query.where(builder.equal(from.type(), builder.literal(from.getJavaType())));
}
#6

Try the test in #3 please. Does it work?

If it works. Try changing it (e.g. following #5) to fail and post the revised test.

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

Build 2.3.4_03 should fix also the type literals problem. Please try it.

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

As said, it still happens with criteria api and it is easy to replicate.

I've created a ticket for it

http://www.objectdb.com/database/issue/112

Thanks!

Alex

#9

Build 2.3.4_04 should complete the fix of this problem.

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

Post Reply

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