-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: DB changes not seen by hibernate query
PostPosted: Mon Aug 08, 2005 7:58 am 
Newbie

Joined: Fri Sep 03, 2004 10:53 am
Posts: 7
In my application, I have Folders that contain Documents.
Recently, I switched from doing folder.getDocuments() plus hand coded filtering to a complex HQL query:

Code:
    private static final String ADMIN_QUERY =
        "from Document d join d.folders f join d.latestVersion v left join d.docType dt " +
        "where d.client = :client and " +
        "f.id = :folderId and (f.isArchiveFolder = false or d.archived = true)";

        Query q = session.createQuery("select d" + ADMIN_QUERY);
        q.setEntity("client", currentUser.getClient())
            .setLong("folderId", folderId)
            .setFirstResult(first)
            .setMaxResults(pageSize)
            .setCacheable(false);

        List<Document> docs = q.list();



Unfortunately, if a user changes a Document, and then runs the above query, the user sees the old version (before the changes). This was not happening when I used the folder.getDocuments().

I have tried changing the cache from ehcache to a null cache implementation, but this has no effect. I have also tried changing to selecting document ids, and then doing a session.load(Document.class, id), also with no success.
I have also tried session.load(Document.class, id, LockMode.READ) which is supposed to skip the cache and read straight from the DB, but still no success.

Two questions: has anyone ever seen this behaviour, and what caused it?
Secondly, how can I tell Hibernate to not use the cache for this query?

Hibernate version: 2.1.8

Name and version of the database you are using: Postgres 8

Ciao,
Jonathan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 12:02 pm 
Regular
Regular

Joined: Fri Jan 28, 2005 3:11 am
Posts: 81
Not sure if this will be helpful or not. I had similar symptoms and was going batty thinking it's something to do with hibernate. In the end I realized, I was simply forgetting to commit my changes.

So let me ask you: are you sure you have properly committed the changes?


Top
 Profile  
 
 Post subject: Solution
PostPosted: Mon Aug 08, 2005 1:01 pm 
Newbie

Joined: Fri Sep 03, 2004 10:53 am
Posts: 7
To aturetsky: my changes were being committed to the DB, and I could see that using various DB tools.

To anybody who might be having the same problem: Its your own fault, not hibernates!

I finally figured out what was going on. I thought it must be a problem with the second level cache, but it was actually a problem with the first-level (Session) cache.

I had two sessions. One was assigned to my query executor using HiveMind (IOC stuff). This session was never closed. So, I would use this session to look at a page of documents, then change one of the documents with a different session, close that session, committing changes to the DB, and then go back to the first already open session to get a new page of Documents. Of course, I never saw any changes in the first session.

Anyway, I learned lots of interesting things about second level caches. I just hope 2 days was worth it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.