You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by "LYALIKOV, Oleg (Oleg)" <ol...@alcatel-lucent.com> on 2014/05/26 15:56:09 UTC

Data cache does not work in OpenJPA 2.2.2

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

Re: Data cache does not work in OpenJPA 2.2.2

Posted by olyalikov <ol...@alcatel-lucent.com>.
I just wanted to post an update about the issue.
We made own release of OpenJPA 2.2.2 with merged fix, we use it ~3 months
and all goes well (tests ok, performance ok).
So if somebody is interested, here are forked and fixed sources:
https://github.com/oamp-cms/openjpa, CI job:
https://buildhive.cloudbees.com/job/oamp-cms/job/openjpa/ and released
binaries on bintray repository:
https://bintray.com/oamp-ale/openjpa/openjpa/view

And thanks Rick for providing commit with fix - it saved our performance
(still better to have official release but anyway),
Oleg




--
View this message in context: http://openjpa.208410.n2.nabble.com/Data-cache-does-not-work-in-OpenJPA-2-2-2-tp7586675p7587084.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.