I've worked through the examples and have got a decent mapping up and running. The problem that I'm running into is when I try to write my own cache.
The situation:
I've got a data object that is accessed several thousand times a minute, but is updated only once every minute or so through a JMS message. The access is through servelets, so both reads and writes are via separate threads.
What I'm currently doing:
I wrote my own cache, that opens up a session, gets all objects of the type, and closes it. then it hands the objects out upon request.
The various readers (through the servlet) do not access the DB, but merely increments an access counter (not persisted) on the object.
The writers (through the onMessage function of the JMS client) gets the object from the cache, updates the object based upon the JMS cache and the access counter, and saves it.
The problem:
If the writer is coded like:
Code:
s = HibernateUtil.currentSession();
tx = s.beginTransaction();
s.saveOrUpdate(blah);
tx.commit();
s.flush();
then I get stale object exceptions eventually. If I add a
s.close(); then everything is fine and dandy. The problem is that I'd like to avoid the call to close, as eventually I'll have a couple hundred of these objects, and close (and the ensuing open) seems to be pretty expensive.
Two questions:
1) Is there something inherently wrong in having Transient objects that aren't really transient? (it really is persistent, but it's not associated with any session.)
2) Does automatic versioning take care of this problem? I read through the documentation and it doesn't seem to address the issue of transient objects and associations with several threads...
thanks for any help.
Jeff