Performance degradation in hibernate SessionImpl get(Class<T> entityClass, Serializable id) method in 5.2.5.version compared to 3.6.10.version

Hi,
We have upgraded our application from old stack to new stack.

Old Stack

  • Java 6

  • Jboss-eap-6.4

  • Hibernate-core : 3.6.10.Final

New Stack

  • Java 8

  • Jboss-eap-7.0

  • Hibernate-core : 5.2.5.Final

We have seen a performance degradation for org.hibernate.impl.SessionImpl.get(Class, Serializable) SessionImpl.java method in new stack. We used to call this method for the persistent instance of the given entity class.

Code
public <T extends SuperJDOIfc> T getEntityFromReferenceCache(Serializable primaryKey, Class<T> entityClass, SessionImpl sessImpl) {
        SuperBasicReferenceJDOIfc jdoIfc = null;
        org.hibernate.annotations.Cache cacheAnn = entityClass.getAnnotation(org.hibernate.annotations.Cache.class);
        if (cacheAnn != null && EhcacheManager.REFERENCE.equals(cacheAnn.region())) {
            if (sessImpl != null && !sessImpl.isClosed()) {
                jdoIfc = (SuperBasicReferenceJDOIfc) sessImpl.get(entityClass, primaryKey);
            }

Calling code : sessImpl.get(entityClass, primaryKey)

We did profiling from yourkit for both the stack and we found below timings:

NEW stack: For 3714 entity it’s around 20 sec.
OLD stack: For 3762 entity it’s around 2 sec.

Old Stack yourkit snapshot image:

New Stack yourkit snapshot image:

How to solve this performance issue. Is there any configuration we need to do or is it a bug ?

PS: Same code is used in both stack.

Thanks.