Probably not. If your stored procedure updates any entities that are cached in the 2nd level cache, Hibernate has no way to know about the update and thus can't invalidate those entities out of the cache. The cached entities thus contain out of date data. (Similar problem applies if you are caching query results.)
When you execute a native SQL statement, Hibernate parses it to see what tables are affected and invalidates all entities from the 2nd level cache that are associated with those tables. But if you are executing a stored procedure, Hibernate doesn't know what will happen.
thank you for reply. Just one more question - the stored procedure is called using native query - so there is no way hibernate can parse or find out what data are affected? If so then it seems that I cannot use distrib cache in my architecture at all :(
You'd be better off asking on a Hibernate forum for exact details of what Hibernate can determine from your query. But in general, if the stored procedure causes a change to happen in the database that isn't expressed in the SQL statement that you ask Hibernate to execute, Hibernate can't figure it out. It's great software but it's not magic. ;)
BTW, this issue is not specific to a distributed 2nd level cache. The same problem exists with a non-distributed 2nd level cache.