Bonjour,
J'ai fait un peu de recherche pour gérer des blob dans topia/hibernate.
Le besoin étant de stocké les fichiers dans la base de données
pour faciliter la gestion.
Solution 1
==========
La première solution que j'ai testé à consister à représenter
les données binaire dans le modèle uml via : java.lang.byte[]
et a changer le type hibernate via model.tagvalue.java.lang.byte[]=binary
ca fonctionnais, mais par contre, le binary a une taille limitée
Solution 2
==========
Même méthode que la solution 1, mais en changeant la tagvalue en
model.tagvalue.java.lang.byte[]=blob
Mais cela ne fonctionne pas non plus:
Caused by: java.lang.ClassCastException: [B cannot be cast to java.sql.Blob
at
org.hibernate.type.descriptor.java.BlobTypeDescriptor.areEqual(BlobTypeDescriptor.java:47)
at
org.hibernate.type.AbstractStandardBasicType.isEqual(AbstractStandardBasicType.java:184)
at
org.hibernate.type.AbstractStandardBasicType.isSame(AbstractStandardBasicType.java:169)
at
org.hibernate.type.AbstractStandardBasicType.isDirty(AbstractStandardBasicType.java:214)
at
org.hibernate.type.AbstractStandardBasicType.isDirty(AbstractStandardBasicType.java:210)
at org.hibernate.type.TypeHelper.findDirty(TypeHelper.java:295)
Solution 3
==========
La solution actuelle à laquelle je suis arrivée mais qui a des
inconvénients de modélisation est la suivante:
* modélisation UML en type : java.sql.Blob
* tag value : model.tagvalue.java.sql.Blob=blob
Mais :
* à l'enregistrement, le code métier doit manipuler des blob
via l’implémentation fournit par hibernate:
is = new FileInputStream(file);
// create blob object
Blob blob = Hibernate.createBlob(is); // code déprécié
is.close();
entity.setData(blob);
* à la lecture (download), actuellement c'est même l'ui struts qui dépent de la
couche sql à cause d'un throws:
public InputStream getInputStream() {
InputStream inputStream = null;
try {
inputStream = analyzeFile.getData().getBinaryStream();
} catch (SQLException ex) {
// damned throws
}
return inputStream;
}
Voilà, j'ai pas de solution plus propre que ca pour le moment.
--
Éric Chatellier <chatellier(a)codelutin.com>
Tel: 02.40.50.29.28
http://www.codelutin.com
The ToPIA team is pleased to announce the topia-2.7 release!
Tools for Portable and Independent Architecture :
Framework de persistance et de distribution d'application.
Documentation of the project can be found here:
http://maven-site.nuiton.org/topia
Important note
--------------
Due to http://nuiton.org/issues/2313, there is some incompatible api in DAO on findAllbyPage method.
You will have to use now the TopiaPagerBean to fix this.
Changes
-------
Changes in this version include:
New features:
o Add methods findAllLazyByQuery on TopiaDAO to iterate on result by a lazy mecanism Issue: 2301. Thanks to Tony Chemit. Resolved by tchemit.
o Improve entity visitor to export as csv files Issue: 2311. Thanks to Tony Chemit. Resolved by tchemit.
o Use new PageBean API from nuiton-utils Issue: 2313. Thanks to Tony Chemit. Resolved by tchemit.
o Add a new method to import a talbe and return imported entities Issue: 2309. Thanks to Tony Chemit. Resolved by tchemit.
o Add progress model while importing data Issue: 2310. Thanks to Tony Chemit. Resolved by tchemit.
Fixed Bugs:
o TopiaCsvExport should use as incoming source Iterable not List Issue: 2302. Thanks to Tony Chemit. Resolved by tchemit.
o CsvFileImportResult does not give back correct entities number Issue: 2306. Thanks to Tony Chemit. Resolved by tchemit.
Changes:
o Updates to nuiton-utils 2.6.2 Issue: 2314. Thanks to Tony Chemit. Resolved by tchemit.
Downloads
---------
No release file deployed. (all files are deployed in the maven repository)
Maven artifacts
---------------
Artifacts are deployed in Maven Central Repository
http://repo1.maven.org/maven2/
Find us at
* http://search.maven.org/#artifactdetails|org.nuiton|topia|2.7|jar
Have fun!
-ToPIA team