-->
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: Problem to update my database when I upload a file
PostPosted: Thu Aug 05, 2004 6:08 am 
Newbie

Joined: Thu Jun 03, 2004 5:47 am
Posts: 13
Hi !

I don't know if you can help me but I try...
There is my problem :
I have a form with file upload and text fields.
When I modify a text field my database is updated but when I modify a file uploaded Hibernate doesn't update my database. I don't know why...

Please help me !!
Thanks in advance !!

My table
Code:
CREATE TABLE alter_theme_couleur (
   idCouleur VARCHAR(45) NOT NULL PRIMARY KEY,
   labelCouleur VARChAR(255),
   valCouleur VARCHAR(45),
   valImage BLOB
);

My bean
Code:
package org.jboss.nukes.core.themes.themeAlter;

import java.sql.Blob;

public final class Couleur {

   private String idCouleur;
   private String labelCouleur;
   private String valCouleur;
   private Blob valImage;
      
   public String getIdCouleur(){
      return idCouleur;
   }
   
   public void setIdCouleur(String idCouleur){
      this.idCouleur = idCouleur;      
   }
      
   public String getLabelCouleur(){
      return labelCouleur;
   }
   
   public void setLabelCouleur(String labelCouleur){
      this.labelCouleur = labelCouleur;      
   }
   
   public String getValCouleur(){
      return valCouleur;
   }
   
   public void setValCouleur(String valCouleur){
      this.valCouleur = valCouleur;
   }
   
   public Blob getValImage(){
      return valImage;
   }

   public void setValImage(Blob valImage){
      this.valImage = valImage;
   }
}


Mapping file
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   
<hibernate-mapping>
  <class name="org.jboss.nukes.core.themes.themeAlter.Couleur" table="alter_theme_couleur">

    <id name="idCouleur" type="string" unsaved-value="null" >
      <column name="idCouleur" sql-type="varchar(45)" not-null="true"/>
      <generator class="uuid.hex"/>
    </id>

    <property name="labelCouleur" column="labelCouleur" type="string" length="255" not-null="false"/>

    <property name="valCouleur" column="valCouleur" type="string" length="45" not-null="false"/>

    <property name="valImage" column="valImage" type="blob" not-null="false"/>
  </class>
</hibernate-mapping>


Code
Code:
Configuration cfg = new Configuration().addClass(Style.class)
            .addClass(Couleur.class)
            .addClass(Param.class)
            .addClass(User.class)   
            .addClass(Image.class);

AccesBD.sessionFactory = cfg.buildSessionFactory();
AccesBD.session = AccesBD.sessionFactory.openSession();

int i = 0;
while (ThemeAlter.couleur[i] != null)  //for each object in my array
{
   Transaction tx = AccesBD.session.beginTransaction();
   ....
   Blob b = ThemeAlter.couleur[i].getValImage();
   b.setBytes(1,byteTab);
   ThemeAlter.couleur[i].setValImage(b);

   AccesBD.session.update(ThemeAlter.couleur[i]);
   tx.commit();
   i++;
}


Hibernate properties
Code:
######################
### Query Language ###
######################

## define query language constants / function names

hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'



#################
### Platforms ###
#################

## MySQL

hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class org.gjt.mm.mysql.Driver
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://localhost:3306/nukes
hibernate.connection.username root
hibernate.connection.password


#################################
### Hibernate Connection Pool ###
#################################

hibernate.connection.pool_size 5

....

##############################
### Proxool Connection Pool###
##############################

## Properties for external configuration of Proxool

hibernate.proxool.pool_alias pool1

# ...
# ...


#######################
### Transaction API ###
#######################

## the Transaction API abstracts application code from the underlying JTA or JDBC transactions

#hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory
#hibernate.transaction.factory_class net.sf.hibernate.transaction.JDBCTransactionFactory

# ...
# ...

##############################
### Miscellaneous Settings ###
##############################

## print all generated SQL to the console

hibernate.show_sql true

## auto schema export

#hibernate.hbm2ddl.auto create-drop
hibernate.hbm2ddl.auto create
#hibernate.hbm2ddl.auto update

## specify a JDBC isolation level

#hibernate.connection.isolation 4

## set the JDBC fetch size

#hibernate.jdbc.fetch_size 25

## set the maximum JDBC 2 batch size (a nonzero value enables batching)

hibernate.jdbc.batch_size 0

## enable use of JDBC 2 scrollable ResultSets (specifying a Dialect will cause Hibernate to use a sensible default)

#hibernate.jdbc.use_scrollable_resultset true

## use streams when writing binary types to / from JDBC

hibernate.jdbc.use_streams_for_binary true

## specify a default schema for unqualified tablenames

#hibernate.default_schema test

## use a custom stylesheet for XML generation (if not specified, hibernate-default.xslt will be used)

#hibernate.xml.output_stylesheet C:/Hibernate/net/sf/hibernate/hibernate-default.xslt

## enable outerjoin fetching (specifying a Dialect will cause Hibernate to use sensible default)

#hibernate.use_outer_join false

## set the maximum depth of the outer join fetch tree

hibernate.max_fetch_depth 1

## enable CGLIB reflection optimizer (enabled by default)

#hibernate.cglib.use_reflection_optimizer false

## enable the query cache

hibernate.cache.use_query_cache true

## choose a cache implementation

# ...

############
### JNDI ###
############

## specify a JNDI name for the SessionFactory

# ...


Top
 Profile  
 
 Post subject: same problem
PostPosted: Wed Jan 17, 2007 2:03 pm 
Newbie

Joined: Thu Jan 11, 2007 1:57 pm
Posts: 9
hi!
i have the same problem. did you fixed it? i have tried but it does not work. hibernate persist the image but if i update the entity encapsulating the image, all other properties become updated but not the image. i set cascade for all actions (persist, merge, refresh and remove).

please, help!


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.