Is there any faster select method?

#1

SELECT:

TypedQuery<Point> query = em.createQuery(
    "SELECT p FROM Point p WHERE p.id = " + element.getId(), Point.class);
List<Point> points = query.getResultList();

WRITE:

em.persist(p);

** the Point class is of the tutorial.

I found the above select method is ten times slower than the write method, in my very simple benchmark.

I guess the reason there is no SQL in the write method.

Is there any faster method of select?

TIA

#2

Entity objects can be retrieved by their primary key (object ID) directly using the find method,  so in this specific case you don't need a SELECT query.

By the way, an invocation of persist is very fast because it is a memory operation, so actually you should compare commit operations and not persist operations with query execution.

 

ObjectDB Support

Reply