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