Announcement Announcement Module
Collapse
No announcement yet.
java.lang.ClassCastException_BlobByteArrayType.deepCopy Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • java.lang.ClassCastException_BlobByteArrayType.deepCopy

    i have some trouble at cast between Blob and org.springframework.orm.hibernate.support.BlobByte ArrayType

    the errro is:

    Code:
    java.lang.ClassCastException
    	at org.springframework.orm.hibernate.support.BlobByteArrayType.deepCopy(BlobByteArrayType.java:85)
    	at net.sf.hibernate.type.CustomType.deepCopy(CustomType.java:142)
    	at net.sf.hibernate.type.TypeFactory.deepCopy(TypeFactory.java:212)
    	at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:926)
    	at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:857)
    	at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:779)
    	at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
    	at org.springframework.orm.hibernate.HibernateTemplate$11.doInHibernate(HibernateTemplate.java:325)
    	at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:200)
    	at org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:322)
    	at com.jctx.trms.hibernate.DAO.FigureFileDAOImpl.addFigureFile(FigureFileDAOImpl.java:16)
    	at com.jctx.trms.hibernate.bussiness.FigureFileManagerImpl.addFigureFile(FigureFileManagerImpl.java:19)
    	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:324)
    	at org.springframework.aop.framework.AopProxyUtils.invokeJoinpointUsingReflection(AopProxyUtils.java:61)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:149)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:116)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:56)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:152)
    	at $Proxy6.addFigureFile(Unknown Source)
    	at com.jctx.trms.propertyui.NetworkUI$1.widgetSelected(NetworkUI.java:272)
    	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:89)
    	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
    	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
    	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2772)
    	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2431)
    	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1377)
    	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1348)
    	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:254)
    	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141)
    	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96)
    	at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335)
    	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
    	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
    	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:324)
    	at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
    	at org.eclipse.core.launcher.Main.run(Main.java:704)
    	at org.eclipse.core.launcher.Main.main(Main.java:688)
    my domain object:

    Code:
    package com.jctx.trms.hibernate.persistence;
    
    import java.sql.Blob;
    
    public class FigureFile extends BaseObject {
    
        private long id;
        
        private Blob figureData;
        
        public FigureFile() {
    
        }
    
        public Blob getFigureData() {
            return figureData;
        }
        public void setFigureData(Blob figureData) {
            this.figureData = figureData;
        }
        public long getId() {
            return id;
        }
        public void setId(long id) {
            this.id = id;
        }
    }
    dao

    Code:
    public class FigureFileDAOImpl extends HibernateDaoSupport implements FigureFileDAO {
    
        public void addFigureFile(FigureFile figureFile) {
            getHibernateTemplate().save(figureFile);
        }
    ..........

    applicationContext.xml

    Code:
    <!-- NativeJdbcExtractor for the Commons DBCP connection pool above -->
    	<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
    			lazy-init="true"/>
    
    	<!-- LobHandler for Oracle JDBC drivers -->
    	<bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler"
    			lazy-init="true">
    		<property name="nativeJdbcExtractor"><ref local="nativeJdbcExtractor"/></property>
    	</bean>
    
        <!-- Hibernate SessionFactory -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
            <property name="dataSource"><ref local="dataSource"/></property>
            <!--  -->    
            <property name="lobHandler"><ref bean="lobHandler" /></property>
    ................
    
        <!-- Transaction -->
        <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
            <property name="sessionFactory">
                <ref local="sessionFactory"/>
            </property>
        </bean>
    
    
        <!-- FigureFile --> 
        <bean id="figureFileDAO" class="com.jctx.trms.hibernate.DAO.FigureFileDAOImpl">
            <property name="sessionFactory">
                <ref local="sessionFactory"/>
            </property>
        </bean>
        <bean id="figureFileManager" parent="txProxyTemplate">
            <property name="target">
                <bean class="com.jctx.trms.hibernate.bussiness.FigureFileManagerImpl">
                    <property name="figureFileDAO"><ref bean="figureFileDAO"/></property>         
                </bean>
            </property>
        </bean>
    
        <!-- Transaction Proxy -->
        <bean id="txProxyTemplate" lazy-init="true"
            class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager">
                <ref bean="transactionManager"/>
            </property>
            <property name="transactionAttributes">
                <props>
                    <prop key="del*">PROPAGATION_REQUIRED</prop>
                    <prop key="add*">PROPAGATION_REQUIRED</prop>
                    <prop key="update*">PROPAGATION_REQUIRED</prop>             
                </props>
            </property>
        </bean>

    hbm.xml

    Code:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping SYSTEM "http&#58;//hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
    
    <hibernate-mapping>
        <class name="com.jctx.trms.hibernate.persistence.FigureFile" table="FIGUREFILE">
            <!--jcs-cache usage="read-only"/-->
    
         <id name="id" 
             column="ID" 
             type="java.lang.Long" 
             unsaved-value="null"
            >
            <generator class="sequence"> 
            </generator>     
         </id>
        
            <property name="figureData" type="org.springframework.orm.hibernate.support.BlobByteArrayType" column="FIGUREDATA" />
                      
        </class>
    </hibernate-mapping>
    the code that insert blob to db。

    Code:
                FigureFile f= new FigureFile&#40;&#41;;
                        LogicDiagram l = new LogicDiagram&#40;&#41;;
                        ByteArrayInputStream bais = null;
                        try &#123;
                            
                            ByteArrayOutputStream baos = new ByteArrayOutputStream&#40;&#41;;
                            ObjectOutputStream oos = new ObjectOutputStream&#40;baos&#41;;
                            oos.writeObject&#40;l&#41;;
                            oos.flush&#40;&#41;;
                            oos.close&#40;&#41;;
                            baos.close&#40;&#41;;
                            bais = new ByteArrayInputStream&#40;baos.toByteArray&#40;&#41;&#41;;
                            bais.close&#40;&#41;;
                       
                            
                        &#125;
                        catch &#40;Exception e1&#41; &#123;
                            e1.printStackTrace&#40;&#41;;
                        &#125;
                                           
                        try &#123;
                            f.setFigureData&#40;Hibernate.createBlob&#40;bais&#41;&#41;;
    
                        &#125;
                        catch &#40;IOException e2&#41; &#123;
                            e2.printStackTrace&#40;&#41;;
                        &#125;
                        catch &#40;SQLException e3&#41; &#123;
                        
                            e3.printStackTrace&#40;&#41;;
                        &#125;
                        //get FigureFileManager  instance
                        FigureFileManager ff = GlobalApplicationContext.getFigureFileManager&#40;&#41;;
                        ff.addFigureFile&#40;f&#41;;

  • #2
    I used BlobByteArrayType successfuly with Oracle RDBMS 10g, Hibernare 2.1.6 and Spring 1.1.2. My domain class however uses byte[] instead of BLOB.
    HTH

    Comment

    Working...
    X