Hmm, I'm wondering if this is something to do with my particular setup.
I tried running some tests with some similar entities in a pure JSE
environment and I don't see the additional queries.
My application where I'm seeing all the additional queries is an Eclipse
RCP app using Spring JPA + Toplink. I wonder if this could be screwing
things up somehow and preventing TopLink from re-using cached entities?
The Spring implementation does seem to have quite a few bell and
whistles including lots of scary class loading and instrumentation add ins.
Confused!
Martin
Martin Bayly wrote:
> When TopLink prints out SQL log statements of the form:
>
> [TopLink Fine]: 2007.01.12
> 12:42:55.578--ClientSession(1293396)--Connection(28404046)--Thread(Thread[main,6,main])--SELECT
> ID, MESSAGESTATUS, SUBJECT, MESSAGEBODY, SENDER_ID, COURSE_ID FROM
> tblCourseMail WHERE (((COURSE_ID = ?) AND (SENDER_ID = ?)) AND
> (MESSAGESTATUS = ?))
> bind => [1, 30026, DRAFT]
>
> ... is this an indication that this SQL is actually being executed
> against the database?
>
> I'm trying to understand some TopLink output - in particular trying to
> understand why something seems a lot slower than I would expect, and
> is even making me wonder whether I've made the wrong choice to try and
> use an ORM mapping solution. But I'm sure I must be doing something
> wrong because I can't really believe it can be this slow.
>
> The above query is loading a bunch of mail messages sent by a
> particular user. Each mail message has a uni-directional ManyToOne
> relationship with the User entity who created it and a uni-directional
> ManyToOne relationship with the Course context for the mail message.
>
> After the above query I see a bunch of queries like these below - so
> it looks like its loading the User and Course entity for each mail
> message loaded. But what I don't understand is why it's issuing these
> select statements so many times? It looks like it is querying the
> user and course for every single mail loaded by the above query even
> though the user id and the course id are the same for every mail
> message. Why is it not just re-using these entities from the
> persistence context once it's loaded them once?
>
> [TopLink Fine]: 2007.01.12
> 12:42:55.578--ClientSession(1293396)--Connection(28404046)--Thread(Thread[main,6,main])--SELECT
> ID, EMAIL, FIRSTNAME, DATETIMESTAMP, LASTNAME, PASSWORD, LOGINNAME
> FROM tblUsers WHERE (ID = ?)
> bind => [30026]
>
> [TopLink Fine]: 2007.01.12
> 12:42:55.593--ClientSession(1293396)--Connection(28404046)--Thread(Thread[main,6,main])--SELECT
> ID, TITLE, DATETIMESTAMP, DESCRIPTION, COURSECONTENTID,
> COURSELIBRARYID FROM tblCourse WHERE (ID = ?)
> bind => [1]
>
> [TopLink Fine]: 2007.01.12
> 12:42:55.593--ClientSession(1293396)--Connection(28404046)--Thread(Thread[main,6,main])--SELECT
> ID, EMAIL, FIRSTNAME, DATETIMESTAMP, LASTNAME, PASSWORD, LOGINNAME
> FROM tblUsers WHERE (ID = ?)
> bind => [30026]
>
> [TopLink Fine]: 2007.01.12
> 12:42:55.609--ClientSession(1293396)--Connection(28404046)--Thread(Thread[main,6,main])--SELECT
> ID, TITLE, DATETIMESTAMP, DESCRIPTION, COURSECONTENTID,
> COURSELIBRARYID FROM tblCourse WHERE (ID = ?)
> bind => [1]
>
> I'm hoping and expecting that I'm doing something very wrong here!
> Any insights?
>
> Thanks
> Martin
>
>