I want to clear cache data from 2nd level cache by calling below method:
sessionFactory.getCache().evictEntityRegions();
I just want to know , is there any harm in doing this? For example: What will happen if I try to clear cache in middle of transaction?
Thanks in advance.
No, there is no harm in doing that. Effectively, the same thing happens when you configure the cache provider to evict/expire items based on the defined eviction/expiration policy.