openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "LYALIKOV, Oleg (Oleg)" <oleg.lyali...@alcatel-lucent.com>
Subject Data cache does not work in OpenJPA 2.2.2
Date Mon, 26 May 2014 13:56:09 GMT
Hello,

I have a simple project with several entities and several relations (a little more complex
than trivial) and when I execute query "SELECT obj FROM MyEntity obj" several times OpenJPA
still executes SQL queries on database to retrieve some data.

Some details: here are entities (you can find full descriptions in the attached project):
Person 1->* DocumentBase
Document 1->* Link1
Document 1->* Link2
and Document entity inherits from DocumentBase entity. All relations are eager OneToMany.

I create one Person with one Document which also has one Link1 and one Link2 objects. Then
I execute query "SELECT DISTINCT obj FROM Person obj" twice and still OpenJPA executes SQL
queries for the second time to retrieve Document/Link1/Link2 data. It makes 2 SQL queries.
If I use following setting (which I primarily interested in):
<property name="openjpa.jdbc.SubclassFetchMode" value="none"/>
then these queries are:

SELECT t0.docName, t1.DOCUMENT_ID, t2.id
    FROM Document t0 LEFT OUTER JOIN Document_Link1 t1 ON t0.id = t1.DOCUMENT_ID
        LEFT OUTER JOIN Link1 t2 ON t1.LINK1_ID = t2.id
    WHERE t0.id = ?
    ORDER BY t1.DOCUMENT_ID ASC
[params=(String) 51]

and

SELECT t1.id
    FROM Document_Link2 t0 INNER JOIN Link2 t1 ON t0.LINK2_ID = t1.id
    WHERE t0.DOCUMENT_ID = ?
[params=(String) 51]

if I use default value for "openjpa.jdbc.SubclassFetchMode" property then anyway 2 queries
are executed:

SELECT t1.id
    FROM Document_Link1 t0 INNER JOIN Link1 t1 ON t0.LINK1_ID = t1.id
    WHERE t0.DOCUMENT_ID = ?
[params=(String) 51]

and

SELECT t1.id
    FROM Document_Link2 t0 INNER JOIN Link2 t1 ON t0.LINK2_ID = t1.id
    WHERE t0.DOCUMENT_ID = ?
[params=(String) 51]

If there are a lot of such objects and a lot of such relations then application just spends
all its time in database. It is serious performance impact...

There is junit test in the attached project which fails in OpenJPA 2.2.2 and it passes in
OpenJPA 2.0.0 so it looks like a regression.

After some analysis it seems that the change was in DataCacheStoreManager::load method. In
the OpenJPA 2.0.0 the method cacheStateManager is executed which properly put fully loaded
objects in cache while in OpenJPA 2.2.2 it firstly check CacheStoreMode, the value is "USE",
the objects are "alreadyCached" (they are actually in cache but only partially loaded) and
so OpenJPA does not update cache and so only partially loaded objects are in cache and so
OpenJPA always executes SQL queries to complete these objects on every query.

So should I post it as a bug in issue tracker? And also maybe you know some workaround for
this issue?

Thanks,
Oleg

Mime
View raw message