-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Save Blob Files with Oracle, WebSphere, Hibernate...
PostPosted: Wed May 05, 2010 3:49 am 
Newbie

Joined: Tue May 04, 2010 11:41 am
Posts: 4
Hi,
I am currently working on an application that saves PDF files to database.
Environment :
WebSphere 5.11
Oracle 9.2
JRE 1.4
Struts 1.3.8
Spring 2
Hibernate 3
Driver ojdbc14-10.2.0.2

In development mode, with Tomcat 4.1, i didn't have problems saving any file (format, size...).
But with WebSphere, the java object, which contains the Blob, is updated with empty Blob. However, I tested with a small file size (4o) and it works !

Configuration :
applicationContext.xml
Code:
    <bean name="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="locations">
           <value>classpath:jdbc.properties</value>
       </property>
    </bean>   
      
   <bean id="dataSource"
      class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close">
      <property name="driverClassName" value="${jdbc.driverClassName}"/>
      <property name="url" value="${jdbc.url}"/>
      <property name="username" value="${jdbc.username}"/>
      <property name="password" value="${jdbc.password}"/>
   </bean>
   
   <bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="mappingLocations">
         <list>
            <value>classpath*:XX.hbm.xml</value>
                                  ...
         </list>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">
               org.hibernate.dialect.Oracle9Dialect
            </prop>    
            <prop key="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
            <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
            <prop key="hibernate.hbm2ddl.auto">none</prop>
            <prop key="hibernate.c3p0.min_size">10</prop>
            <prop key="hibernate.c3p0.max_size">30</prop>
            <prop key="hibernate.c3p0.timeout">100</prop>
            <prop key="hibernate.c3p0.max_statements">0</prop>
            <prop key="hibernate.jdbc.batch_size">0</prop>
            <prop key="hibernate.connection.autocommit">false</prop>
         </props>
      </property>
      <property name="dataSource">
         <ref bean="dataSource" />
      </property>
   </bean>

   <bean id="jdbcExceptionTranslator"
      class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
      <property name="dataSource">
         <ref bean="dataSource" />
      </property>
   </bean>

   <bean id="hibernateTemplate"
      class="org.springframework.orm.hibernate3.HibernateTemplate">
      <property name="sessionFactory">
         <ref bean="sessionFactory" />
      </property>
      <property name="jdbcExceptionTranslator">
         <ref bean="jdbcExceptionTranslator" />
      </property>
   </bean>

   <bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory">
         <ref local="sessionFactory" />
      </property>
   </bean>

Business Object :
Code:
public class NavetteOuvertureBO extends AbstractBO {

    private static final long serialVersionUID = -5268286348123584857L;
    ...
    private Blob blobFicheSignee;

    /**
     * Retourne la propriété blobFicheSignee
     * @return blobFicheSignee
     */
    public Blob getBlobFicheSignee() {
        return blobFicheSignee;
    }

    /**
     * Modifie la propriété blobFicheSignee
     * @param blobFicheSignee nouvelle valeur de blobFicheSignee
     */
    public void setBlobFicheSignee(Blob blobFicheSignee) {
        this.blobFicheSignee = blobFicheSignee;
    }

Mapping hibernate file :
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="xx.xx.xx.NavetteOuvertureBO" table="FICHE_OUVERTURE">
      <id name="id" column="ID_FICHE_OUVERTURE">
         <generator class="sequence">
            <param name="sequence">SEQ_FICHE_OUVERTURE</param>
         </generator>
      </id>
                ...
      <property name="blobFicheSignee" type="blob"
         column="BLOB_FICHE_SIGNEE" lazy="true"/>
   </class>
</hibernate-mapping>

Business Service :
Code:
public void signerNavetteBO(Long id, byte[] fichier, String fileName) throws ApplicationException {
         Blob blobFicheSignee = Hibernate.createBlob(fichier);
         ficheNavetteBO.setBlobFicheSignee(blobFicheSignee);
         ficheNavetteBO.setNomFicheSignee(fileName);
         this.getNavetteFermetureDAO().updateNavetteFermetureBO(ficheNavetteBO);

And the DAO :
Code:
    public void updateNavetteOuvertureBO(NavetteOuvertureBO navette) throws TechnicalException {
        NavetteOuvertureBO ancienneNavette = this.getNavetteOuvertureBO(navette.getId());
        if (ancienneNavette == null) {
            throw new TechnicalException(ExceptionMessages.ERREUR_TECHNIQUE_CONCURRENT_SUPPRESSION);
        }
        this.getHibernateTemplate().evict(ancienneNavette);
        this.getHibernateTemplate().update(navette);
    }

I searched on many forums: changing properties hibernate, use the OCI driver without success.
Thank you for your help


Top
 Profile  
 
 Post subject: Re: Save Blob Files with Oracle, WebSphere, Hibernate...
PostPosted: Thu May 06, 2010 4:09 am 
Newbie

Joined: Tue May 04, 2010 11:41 am
Posts: 4
Excuse me stress but I do not find solution to my problem...

I test to save differents sizes of files and it works for file sizes less than 2ko. For a larger file, an update is done but the blob raw is null.
In different forums, i saw that solution was to change oracle driver version. I try ojdbc14-10.2.0.2, 10.2.0.4 and 9.2.0.8 without success.

Could it be the pool connexion size?
Use OCI driver rather than thin driver?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.