question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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,

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
qhr-slavacommented, 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 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.

0reactions
wilkinsonacommented, Jan 11, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.ClassCastException: com.sun.proxy.$Proxy62 ...
java.lang.ClassCastException: com.sun.proxy.$Proxy62 cannot be cast to org.hibernate.engine.spi.SessionImplementor ; spring.version · 5.3.1 ...
Read more >
ClassCastException when unwrapping proxied EntityManager
EntityManager$470189163$Proxy$_$$_WeldClientProxy cannot be cast to org.hibernate.engine.spi ... WELD-1498 ClassCastException when proxied class return this.
Read more >
Javassist ClassCastException after switching from 4.2.7.SP1 ...
Vendor_$$_javassist_9 cannot be cast to javassist.util.proxy.Proxy. We are re-check environment and ... 25 at org.hibernate.engine.query.spi.HQLQueryPlan.
Read more >
java.lang.ClassCastException: $ProxyXXX cannot be cast to
The docroot/WEB-INF/service directory contains the entity POJO interfaces, the XxxLocalServiceUtil classes, the class loader proxy stuff, ...
Read more >
Uses of Interface org.hibernate.engine.spi.SessionImplementor
This package abstracts the notion of a "property" of an entity. org.hibernate.proxy. This package defines a framework for lazy-initializing entity proxies. org.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found