java.lang.ClassCastException: org.hibernate.internal.StatelessSessionImpl cannot be cast to org.hibernate.Session

Stack Overflow | longtimer | 6 months ago
  1. 0

    StatelessSession being cast to Session in AbstractEntityPersister (Hibernate)

    Stack Overflow | 6 months ago | longtimer
    java.lang.ClassCastException: org.hibernate.internal.StatelessSessionImpl cannot be cast to org.hibernate.Session
  2. 0

    AbstractQueryImpl#guessType casts SessionImplementor session to Session but StatelessSession does not implement Session. Simple test: @Test public void testStatelessSession() throws Exception { StatelessSession statelessSession = sessionFactory.openStatelessSession(); String queryString = "Select * from Papa where partition_id = :partition"; SQLQuery query = statelessSession.createSQLQuery(queryString); PartitionImpl partition = new PartitionImpl("part02"); query.setParameter("partition", partition); assertThat(query.list().size(), is(0)); } Throws Exception: java.lang.ClassCastException: org.hibernate.internal.StatelessSessionImpl cannot be cast to org.hibernate.Session at org.hibernate.internal.AbstractQueryImpl.guessType(AbstractQueryImpl.java:553) at org.hibernate.internal.AbstractQueryImpl.guessType(AbstractQueryImpl.java:534) at org.hibernate.internal.AbstractQueryImpl.determineType(AbstractQueryImpl.java:519) at org.hibernate.internal.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:487) at de.pds.common.hibernatetest.HibernateTest.testStatelessSession(HibernateTest.java:2667) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

    Hibernate JIRA | 5 months ago | Holger Niehaus
    java.lang.ClassCastException: org.hibernate.internal.StatelessSessionImpl cannot be cast to org.hibernate.Session
  3. 0
    When you have no build parameters, uncheck 'This build is parameterized'
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Cast Exception while trying to getDelegate() from EntityManager

    Oracle Community | 8 years ago | ziphyre
    java.lang.ClassCastException: org.hibernate.ejb.EntityManagerImpl cannot be cast to org.hibernate.Session >
  6. 0

    java.lang.ClassCastException: org.hibernate.impl.SessionFactoryImpl cannot be cast to org.hibernate.

    Coderanch | 3 years ago | umesh annegirikar
    java.lang.ClassCastException: org.hibernate.impl.SessionFactoryImpl cannot be cast to org.hibernate.Session

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      org.hibernate.internal.StatelessSessionImpl cannot be cast to org.hibernate.Session

      at org.hibernate.persister.entity.AbstractEntityPersister.preInsertInMemoryValueGeneration()
    2. Hibernate
      StatelessSessionImpl.insert
      1. org.hibernate.persister.entity.AbstractEntityPersister.preInsertInMemoryValueGeneration(AbstractEntityPersister.java:3591)
      2. org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3568)
      3. org.hibernate.internal.StatelessSessionImpl.insert(StatelessSessionImpl.java:144)
      4. org.hibernate.internal.StatelessSessionImpl.insert(StatelessSessionImpl.java:123)
      4 frames
    3. com.mycompany.somepackage
      DaPostInsertUpdateEventListener.onPostInsert
      1. com.mycompany.somepackage.dao.impl.CommonDAOImpl.persist2(CommonDAOImpl.java:242)
      2. com.mycompany.somepackage.publisher.ScJournalPublisher.publish(ScJournalPublisher.java:37)
      3. com.mycompany.somepackage.annotation.callback.CallbackInvoker.invokePublisherCallback(CallbackInvoker.java:92)
      4. com.mycompany.somepackage.event.listener.DaPostInsertUpdateEventListener.onPostInsert(DaPostInsertUpdateEventListener.java:51)
      4 frames
    4. Hibernate
      AbstractTransactionImpl.commit
      1. org.hibernate.action.internal.EntityInsertAction.postInsert(EntityInsertAction.java:177)
      2. org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:145)
      3. org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465)
      4. org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351)
      5. org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
      6. org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
      7. org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1258)
      8. org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:425)
      9. org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
      10. org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
      10 frames
    5. Spring ORM
      HibernateTransactionManager.doCommit
      1. org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:584)
      1 frame
    6. Spring Tx
      TransactionInterceptor.invoke
      1. org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)
      2. org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)
      3. org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:521)
      4. org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
      5. org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
      5 frames
    7. Spring AOP
      CglibAopProxy$DynamicAdvisedInterceptor.intercept
      1. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      2. org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
      2 frames