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 beanCode:
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 fileCode:
<?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>
CodeCode:
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 propertiesCode:
######################
### 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
# ...