code: public static void setObjectToReadyOnly(Object target, SessionFactory sessionFactory) {
          Object resource = TransactionSynchronizationManager.getResource(sessionFactory);
          if(resource != null) {
              Session session = sessionFactory.getCurrentSession();
              if (canModifyReadWriteState(session, target)) {
                  if (target instanceof HibernateProxy) {
                      target = ((HibernateProxy)target).getHibernateLazyInitializer().getImplementation();
                  }
                  session.setReadOnly(target, true);
                  session.setHibernateFlushMode(FlushMode.MANUAL);
              }
          }
      }
docs: Sets the target object to read-only using the given SessionFactory instance. This
  avoids Hibernate performing any dirty checking on the object
  
  @see #setObjectToReadWrite(Object, org.hibernate.SessionFactory)
  
  @param target The target object
  @param sessionFactory The SessionFactory instance