You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by "M. Walter" <ma...@sbb.ch> on 2011/09/13 14:21:10 UTC

Join fetch does not work if data cache is enabled

In my persistence.xml I enabled the data cache:

<property name="openjpa.DataCache" value="true(CacheSize=10000)" />

I used a named query "SELECT p FROM Parent p LEFT JOIN FETCH p.children" to
load the childrens' list eagerly which is configured lazy in the Parent
entity.

The Parent entity then was requested from a remote client.

The first time the query was executed the client received the parent with
the list of children. In the trace I could see OpenJPA executing a SELECT
from the database.

The second time the query was executed the client received the parent but
the list of children was null (and stayed null for all subsequent requests).
There was no SELECT fired anymore.

openjpa.jdbc.JDBC: Trace: Initial connection autoCommit: true, holdability:
1, TransactionIsolation: 2
openjpa.jdbc.JDBC: Trace: <t 1391284973, conn 2070182756> [0 ms] close
openjpa.jdbc.JDBC: Trace: <t 1391284973, conn 711993968> [0 ms] close
openjpa.Query: Trace: Executing query: SELECT p FROM Parent p LEFT JOIN
FETCH p.childrenList
openjpa.jdbc.SQL: Trace: <t 1391284973, conn 2114092546> executing prepstmnt
54657858 SELECT [lots of attributes] FROM PARENT t0, LINIE t1 WHERE t0.ID =
t1.PARENT_ID(+)
openjpa.jdbc.SQL: Trace: <t 1391284973, conn 2114092546> [187 ms] spent
openjpa.jdbc.JDBC: Trace: <t 1391284973, conn 2114092546> [15 ms] close
openjpa.Query: Trace: Executing query: SELECT p FROM Parent p LEFT JOIN
FETCH p.childrenList
openjpa.Query: Trace: Executing query: SELECT p FROM Parent p LEFT JOIN
FETCH p.childrenList

This "behaviour" went away as soon as I removed the data cache property from
the persistence.xml.

Is this a bug in the data cache? Seems like it "forgets" to fill the list
after the first request.

OpenJPA 1.2.3 is used.

--
View this message in context: http://openjpa.208410.n2.nabble.com/Join-fetch-does-not-work-if-data-cache-is-enabled-tp6787245p6787245.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Join fetch does not work if data cache is enabled

Posted by Michael Dick <mi...@gmail.com>.
OpenJPA has historically had problems with JOIN FETCH syntax, but this
sounds like a new bug.

Would you be adverse to trying OpenJPA's fetch plans instead? I mentioned it
in this post : http://markmail.org/message/wrqdyc22b2gaocux, and there's
some information in the manual at:
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_runtime_jpafetch.


In general fetch plans work more reliably with OpenJPA, and they might be a
workaround for you while we work on the bug.

hth
-mike

On Fri, Sep 23, 2011 at 8:07 AM, M. Walter <ma...@sbb.ch> wrote:

> I wonder if I'm the first developer stumbling upon this one...
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Join-fetch-does-not-work-if-data-cache-is-enabled-tp6787245p6824153.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: Join fetch does not work if data cache is enabled

Posted by "M. Walter" <ma...@sbb.ch>.
I wonder if I'm the first developer stumbling upon this one...

--
View this message in context: http://openjpa.208410.n2.nabble.com/Join-fetch-does-not-work-if-data-cache-is-enabled-tp6787245p6824153.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.