Springboot version: 2.6.2

I use this like:

  DetachedCriteria criteria = DetachedCriteria.forClass(User.class);
  criteria.add(Restrictions.eq("code", code));
  Session session = sessionFactory.getCurrentSession();
  criteria.getExecutableCriteria(session);

I get a error:

java.lang.ClassCastException: class com.sun.proxy.$Proxy110 cannot be cast to class org.hibernate.engine.spi.SessionImplementor (com.sun.proxy.$Proxy110 and org.hibernate.engine.spi.SessionImplementor are in unnamed module of loader 'app')
    at org.hibernate.criterion.DetachedCriteria.getExecutableCriteria(DetachedCriteria.java:67) ~[hibernate-core-5.6.3.Final.jar:5.6.3.Final]
    at c.d.c.r.c.createCriteria(CommonRepository.java:123) 
       ....
       ....


Can you give me some advice?

Thanks,

Comment From: philwebb

Not with such limited information I'm afraid. It's not clear if this is a misconfiguration or a bug and if there is a problem it's not clear if it's with Spring Boot, Hibernate or something else. I would suggest asking on stackoverflow.com and providing a small project that replicates the issue.

Comment From: ghost

@philwebb it sounds like the same problem as this one https://github.com/spring-projects/spring-framework/issues/26090 I get the same problem after upgrading to spring boot 2.6.2

Comment From: philwebb

Thanks @qhr-slava!

@xiaoquanWu, you might want to try the latest Spring Boot version to see if it's fixed.

Comment From: ghost

@philwebb happens in 2.6.2, just checked

Comment From: philwebb

@qhr-slava Are you able to provide a sample project that shows the issue? It looks like we've marked https://github.com/spring-projects/spring-framework/issues/26090 as fixed so perhaps this is something else.

Comment From: wilkinsona

Arguably, this is a bug in Hibernate. It assumes that a Session will also be a SessionImplementor and makes an unchecked cast.

I think you can work around this by unwrapping. Rather than passing session into getExecutableCriteria, try passing in the result of session.unwrap(SessionImplementor.class) instead.

Comment From: ghost

@philwebb @wilkinsona just figured that I need to check versions for hibernate-search-orm in my app, didn't do it yesterday. One of parent's pom there has [INFO] | - org.hibernate:hibernate-search-orm:jar:5.9.0.Final:compile and according to https://github.com/spring-projects/spring-framework/issues/26090 I need at least 5.11.6 for Hibernate Search to work. I assume that @xiaoquanWu has similar issue.

FullTextEntityManager getFullTextManager() { return Search .getFullTextEntityManager(entityManager.getEntityManagerFactory().createEntityManager()); } this is the place where everything fails in my case.