Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class com.sun.proxy.$Proxy cannot be cast to class org.hibernate.engine.spi.SessionImplementor #29155

Closed
xiaoquanWu opened this issue Dec 23, 2021 · 7 comments
Labels
for: external-project For an external project and not something we can fix

Comments

@xiaoquanWu
Copy link

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,

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 23, 2021
@philwebb
Copy link
Member

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.

@philwebb philwebb added for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 11, 2022
@ghost
Copy link

ghost commented Jan 11, 2022

@philwebb it sounds like the same problem as this one spring-projects/spring-framework#26090
I get the same problem after upgrading to spring boot 2.6.2

@philwebb
Copy link
Member

Thanks @qhr-slava!

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

@ghost
Copy link

ghost commented Jan 11, 2022

@philwebb happens in 2.6.2, just checked

@philwebb
Copy link
Member

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

@philwebb philwebb reopened this Jan 11, 2022
@philwebb philwebb added status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged and removed for: stackoverflow A question that's better suited to stackoverflow.com labels Jan 11, 2022
@wilkinsona
Copy link
Member

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.

@ghost
Copy link

ghost commented Jan 11, 2022

@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 spring-projects/spring-framework#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.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 11, 2022
@philwebb philwebb added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

4 participants