class com.sun.proxy.$Proxy cannot be cast to class org.hibernate.engine.spi.SessionImplementor
See original GitHub issueSpringboot 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:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.Arguably, this is a bug in Hibernate. It assumes that a
Session
will also be aSessionImplementor
and makes an unchecked cast.I think you can work around this by unwrapping. Rather than passing
session
intogetExecutableCriteria
, try passing in the result ofsession.unwrap(SessionImplementor.class)
instead.