292 words

Issue #112 - Issue with TYPE expression in Criteria API

BugVersion: Priority: NormalStatus: FixedReplies: 2
#1
2011-12-08 07:31

Find attached project using latest 2.3.4_03 odb still causes:

 

Query: SELECT $1 FROM com.test.virtual.model.MyCustomer $1 WHERE TYPE($1)=class com.test.model.Customer
Exception in thread "main" [ObjectDB 2.3.4_03] javax.persistence.PersistenceException
Attempt to store an instance of a non persistable type java.lang.Class (error 303)
at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:675)
at com.test.TestRun.test01(TestRun.java:68)
at com.test.TestRun.main(TestRun.java:28)
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.getResultList(JpaQuery.java:666)
... 2 more
quasado
quasado's picture
Joined on 2011-04-30
User Post #37
#2
2011-12-08 13:17

Thank you for this bug report.

In the future, please submit tests using a single file format (when applicable) as explained in the posting instructions. For example, your test can be simplified (after removing unnecessary code) to:

import java.util.*;
 
import javax.persistence.*;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
 
public class I112 {
 
    public static void main(String[] args) {
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory(
                "objectdb://localhost:6136/test/test.tmp;drop;admin");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        em.persist(new Contact("Contact One"));
        em.persist(new Contact("Contact Two"));
        em.persist(new Customer("Customer One"));
        em.persist(new Customer("Customer Two"));
        em.getTransaction().commit();
        em.close();
 
        em = emf.createEntityManager();
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<Object> cq = cb.createQuery();
        Root<Customer> e = cq.from(Customer.class);
        cq.select(e);
        cq.where(cb.equal(e.type(), cb.literal(e.getJavaType())));
        System.out.println("Query: " + cq);
        List<Object> resultList = em.createQuery(cq).getResultList();
        System.out.println("Size: " + resultList.size());
        em.close();
        emf.close();
    }
 
    @Entity
    public static class Contact {
        private String name = null;
        public Contact(String name) {
            this.name = name;
        }
 
        public Contact() {
        }
    }
 
    @Entity
    public static class Customer extends Contact {
        public Customer(String name) {
            super(name);
        }
        public Customer() {
        }
    }
}

Actually this is very similar to the test on this forum thread except that your test uses client server mode. Both work well (also in client server mode) when serialization is enabled in the configuration (under <entities>):

    <persist serialization="true" />

This is required because currently passing a type argument (a Class instance) in client-server mode requires serialization. Following your report, this will be fixed in next builds.

Thanks again for this bug report.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #783
#3
2011-12-09 03:37

Starting build 2.3.4_04 the test should also pass with serialization disabled.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #785

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel