ObjectDB ObjectDB

how explorer queries work

#1

i'm curious as to how the explorer is able to execute queries when its obviously not aware of the object model that i built. the reason is because i have an application where i want to be able to execute somewhat generalized queries and i won't know what classes are in the object model ahead of time.

this is especially curious to me in client-server mode since the .jar with the object model classes is on the server side, not the client side where explorer is running.

i can figure out how to load the classes in a .jar at runtime but i can't see how i would tell the entity manager that they're entities. (obviously the explorer must be doing something like this; correct me if i'm wrong.) is this part of the public interface in JPA? would it have to be objectDB-specific? is explorer just faking it somehow?

edit
delete
#2

ObjectDB stores the schema in the database (in the odb file) so it doesn't need the classes for running ordinary queries.

However, if you use user defined methods in queries (ObjectDB supports it as an extension to JPA/JDO but it should be used carefully) you have to add your classes to the classpath of the Explorer and the Server, since methods are not stored in the database.

ObjectDB Support
edit
delete
#3

the specific problem i can't get over is, even with all the classes loaded, an untyped query:

List result = em.createQuery(queryString).getResultList();

throws an exception like this:

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
        at java.lang.Thread.run(Thread.java:636)
Caused by: com.objectdb.o.InternalException: Unexpected internal exception
        at com.objectdb.o.CLS.T(CLS.java:367)
        at com.objectdb.o.CLS.S(CLS.java:329)
        at com.objectdb.o.CLS.Q(CLS.java:274)
        at com.objectdb.o.CST.UO(CST.java:499)
        at com.objectdb.o.QRR.g(QRR.java:232)
        at com.objectdb.o.QRR.b(QRR.java:151)
        at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:686)
        at foo.TestQuery.transact(TestQuery.java:154)
        at foo.TestQuery.main(TestQuery.java:403)
        ... 6 more
Caused by: com.objectdb.o.UserException: Failed to deserialize (com.objectdb.o.HMP$F; local class incompatible: stream classdesc serialVersionUID = 7888310505984857729, local class serialVersionUID = -4638987908756508097)
        at com.objectdb.o.MSG.d(MSG.java:74)
        at com.objectdb.o.BYR.ac(BYR.java:807)
        at com.objectdb.o.BYR.ac(BYR.java:747)
        at com.objectdb.o.CLS.T(CLS.java:361)
        ... 14 more
Caused by: java.io.InvalidClassException: com.objectdb.o.HMP$F; local class incompatible: stream classdesc serialVersionUID = 7888310505984857729, local class serialVersionUID = -4638987908756508097
        at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:579)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1600)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1513)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1749)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
        at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1684)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1340)
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1963)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1887)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1963)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1887)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)
        at com.objectdb.o.BYR.ac(BYR.java:782)
        ... 16 more

even if it is just SELECT a FROM Apple a or SELECT Orange o, and even with some freaky class loading of bar.Apple going on successfully beforehand.

with the class loaded, my thinking was that i just needed to make ObjectDB aware of it somehow.

edit
delete
#4

This is not an Explorer related question.

Please follow the posting instructions and use a new separate thread for this new question.

ObjectDB Support
edit
delete
#5

well perhaps my choice of topic is what's incorrect.

explorer executes a user's JPQL query and it certainly doesn't have my object model available to it. does it do it without EntityManager and Query? does it do it in an ObjectDB-specific manner? i'm interested in similar functionality, but i need to work with the object model as well, even if i have to avail to dynamic class loading, reflection, etc.

edit
delete
#6

ObjectDB knows to build missing entity and embeddable classes, based on the schema that is internally stored in the database file. Therefore, you should be able to query an existing database also without your classes.

The stack trace at #3 indicates that you are using serializable types and that the version of the serialized class on persisting is different than the version of the serialized class or retrieval. If you build your classes dynamically it could definitely explain the mismatching.

Try to avoid using user defined serializable non entity / embeddable classes (which are not recommended anyway) and use embeddable classes instead. This way ObjectDB will be able to complete your missing classes.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.