sauvgarder un fichier doc ou pdf dans Mysql avec hibernate
slt tous,
je veux inserer un uploadedFile de type pdf ou doc dans une table de ma base de données mais j'arrive pas a réussir
Ma class Document
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
package document_pack;
import java.io.IOException;
import org.apache.myfaces.custom.fileupload.UploadedFile;
public class Document {
private String name;
private byte[] content;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setContent(UploadedFile file) throws IOException {
this.content = file.getBytes();
}
public byte[] getContent() {
return content;
}
} |
ma methode
Code:
1 2 3 4 5 6 7 8 9 10
| public void savefile(UploadedFile file,String name) throws IOException, SQLException{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx =session.beginTransaction();
Document doc =new Document();
doc.setName(name);
doc.setContent(file);
session.save(doc);
tx.commit();
} |
mon fichier map
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 20 sept. 2009 00:54:17 by Hibernate Tools 3.2.5.Beta -->
<hibernate-mapping>
<class name="document_pack.Document" entity-name="Document" table="DOCUMENT" proxy="Document">
<id name="name" type="java.lang.String">
<column name="NAME" />
<generator class="assigned"/>
</id>
<property name="content" type="byte[]">
<column sql-type="BLOB" name="CONTENT" />
</property>
</class>
</hibernate-mapping> |
erruer: Found some error : java.io.FileNotFoundException:
merci d'avance