-->
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: Invalidating Space happens after every native SQL execution
PostPosted: Mon Dec 07, 2009 2:58 pm 
Newbie

Joined: Wed Nov 25, 2009 8:22 pm
Posts: 2
I am using an EhCache for my second level cache and I have run into an issue where everytime I execute session.CreateSQLQuery(), the cache discards all objects. I use the createSQLQuery to execute a table level lock on a table (I am using a database which requires a LOCK FOR ACCESS in order to allow concurrent reads and writes to be executed on a table), and within the same transaction is modify objects from the table or the cache.

So say that I have the following code:

Code:
public List<TestObject> readAll() throws Exception {
        Session sess = HibernateSessionFactory.getSessionFactory().getCurrentSession();
        sess.beginTransaction();
        sess.createSQLQuery("LOCK TABLE TEST_OBJECT FOR ACCESS").executeUpdate();
        sess.setCacheMode(CacheMode.NORMAL);
        List<TestObject> objs = sess.createQuery("from TestObject as tst").setLockMode("tst", LockMode.FORCE).setCacheable(true).list();
        sess.getTransaction().commit();
        return objs;
    }


Once this executes all the objects from the TEST_OBJECT table are loaded into memory. Once the transaction is committed, the following debug message appears:

Invalidating space [TEST_OBJECT], timestamp: 5161828781969408


Then once I attempt to retrieve objects from the cache:

Code:
public TestObject read(String uuid) {
        Session sess = HibernateSessionFactory.getSessionFactory().getCurrentSession();
        sess.beginTransaction();
        sess.setCacheMode(CacheMode.NORMAL);
        TestObject obj = (TestObject) sess.get(TestObject.class, uuid);
        sess.getTransaction().commit();
        return obj;
    }


I keep getting the invalidate space message and queries are executed against the database.

So I have 2 questions:

1. Is there a way to have hibernate prepend that Lock table statement prior to each query that it makes to the database?

Or

2. Is there a way to execute the native query without invalidating the cache?

Thanks


Top
 Profile  
 
 Post subject: Re: Invalidating Space happens after every native SQL execution
PostPosted: Wed Jan 13, 2010 11:21 pm 
Newbie

Joined: Wed Jan 13, 2010 11:18 pm
Posts: 2
I am facing the same problem. Will let you know if found any solution.


Top
 Profile  
 
 Post subject: Re: Invalidating Space happens after every native SQL execution
PostPosted: Thu Jan 14, 2010 2:28 am 
Newbie

Joined: Wed Jan 13, 2010 11:18 pm
Posts: 2
just found the solution, add the following line to your named sql:

<sql-query name="setDbSecurityContext" >
<synchronize table="" />
{ call final_jkr_pkg_policy.pr_setuser(?) }
</sql-query>

This will tell hibernate which cache need to be invalidated. If no synchronize is set, hibernate will invalidate all spaces.


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.