[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-5550) Hibernate.createBlob() fails when used in current_session_context_class=thread mode

Steve Ebersole (JIRA) noreply at atlassian.com
Wed Jan 5 11:11:07 EST 2011


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5550?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Steve Ebersole updated HHH-5550:
--------------------------------

         Assignee: Steve Ebersole
    Fix Version/s: 3.6.1

> Hibernate.createBlob() fails when used in current_session_context_class=thread mode
> -----------------------------------------------------------------------------------
>
>                 Key: HHH-5550
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5550
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.5.5
>            Reporter: Zemian Deng
>            Assignee: Steve Ebersole
>             Fix For: 3.6.1
>
>
> See https://forum.hibernate.org/viewtopic.php?f=1&t=1004366
> Here is a unit test failed case:
> {code:java}
> package deng.hibernate.examples.blob;
> import org.hibernate.*;
> import org.hibernate.cfg.*;
> import org.junit.Test;
> public class HibernateCreateBlobFailedCase {
> 		
> 	@Test
> 	public void createBlob() {
> 		Configuration cfg = new Configuration();
> 		SessionFactory sessionFactory = cfg.configure().buildSessionFactory();
> 		Session session = sessionFactory.getCurrentSession();
> 		Transaction tx = null;
> 		try {
> 			tx = session.beginTransaction();
> 			byte[] blobBytes = new byte[]{};
> 			Hibernate.createBlob(blobBytes, session);
> 		} catch (Throwable e) {
> 			tx.rollback();
> 			throw new RuntimeException(e);
> 		} finally {
> 			sessionFactory.close();
> 		}
> 	}
> 	
> }
> {code}
> Set hibernate.cfg.xml with thread session context
> {code:xml}
> ...
> <property name="current_session_context_class">thread</property>
> ...
> {code}
> You will get this stack trace
> {noformat}
> java.lang.RuntimeException: java.lang.ClassCastException: $Proxy4 cannot be cast to org.hibernate.engine.jdbc.LobCreationContext
> 	at deng.hibernate.examples.blob.HibernateCreateBlobFailedCase.createBlob(HibernateCreateBlobFailedCase.java:24)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> 	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> 	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> 	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> 	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
> 	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)
> Caused by: java.lang.ClassCastException: $Proxy4 cannot be cast to org.hibernate.engine.jdbc.LobCreationContext
> 	at org.hibernate.Hibernate.getLobCreator(Hibernate.java:502)
> 	at org.hibernate.Hibernate.getLobCreator(Hibernate.java:498)
> 	at org.hibernate.Hibernate.createBlob(Hibernate.java:494)
> 	at deng.hibernate.examples.blob.HibernateCreateBlobFailedCase.createBlob(HibernateCreateBlobFailedCase.java:21)
> 	... 22 more
> {noformat}
> As described in forum, this problem occurred because the session object we get using {{sessionFactory.getCurrentSession();}} is an wrapped ThreadLocalSessionContext instance that can not be cast into LobCreationContext. There is no easy way to unwrap and get the original session object, to pass to createBlob method.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list