Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Does Hibernate query objects in memory in addition to the database?

Thread view: 
david.karr - 05 Apr 2007 19:57 GMT
I'm using Hibernate 3.0.5, JDK 1.4.2, and WebLogic 8.1.4.

I discovered something odd in how a Hibernate query was behaving.
>From what I can tell, the behavior makes me think that when a
Hibernate query executes, it doesn't just query the database, but it
also queries any existing mapped objects in memory, which have not
been created in the database yet.

Before I started my test case, I used SQLDeveloper to verify that my
particular table was empty.  My test case code first "new"s a bunch of
objects that are mapped to this table through Hibernate, but I only
put each one of them into a list.  After that loop, I executed a
Hibernate query on that table, in order to delete the rows that it
finds.  Surprisingly, the query didn't return 0 rows.  It appeared to
return results for the objects that I had just created, but had not
persisted. After that code, it's supposed to persist those "new"ed
objects into the database. Unfortunately, in my test case, it never
gets there, because the transaction times out after executing the
"delete" statements for the allegedly existing rows.

I then rearranged my code so that the query for delete runs first, and
then it goes through the loop that "new"s the objects and then later
persists those.  With the code in this order, it works fine.

Is this along the lines of expected behavior?  I'm still trying to
understand the ramifications of this.
Adam Maass - 06 Apr 2007 05:20 GMT
> I'm using Hibernate 3.0.5, JDK 1.4.2, and WebLogic 8.1.4.
>
[quoted text clipped - 22 lines]
> Is this along the lines of expected behavior?  I'm still trying to
> understand the ramifications of this.

A simple "new" should not have resulted in the new objects being returned by
the query. However, new objects that have been through a session.save() (or
likewise) should have. Before Hibernate runs a query, it flushes (but does
not commit) all pending changes to the database; the database should query
inserted or updated records just like it queries records that have not been
written to yet in this transaction. This way, queries run on the current
state of the objects, even if that state has been modified in the current
session.

Hmmm -- an "insert" followed by a "delete" should be legal on the same row
in the same transaction, but from the sounds of it, is not what you were
expecting.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.