Ich brauche InputStream oder Byte [] (Profilbild) in der Tabelle mit Hibernate zu speichern. hier Code:Bild speichern Hibernate mit sql (don't hql)
@Override
public void actualizarFotoPerfil(String id, byte[] image) throws CotrafaException {
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
String sql = "UPDATE TS_USU_FOTOS SET FOTO = ? WHERE CLIENTE = ?";
SQLQuery query = session.createSQLQuery(sql);
Blob b = Hibernate.createBlob(image);
query.setParameter(0, b.toString());
query.setParameter(1, id);
query.executeUpdate();
session.flush();
}
Tabelle in BD
create table TS_USU_FOTOS
(
cliente NUMBER(8) not null,
foto BLOB
)
und Fehler ist: Verursacht durch: java.sql.SQLSyntaxErrorException: ORA-00932: tipos de Dato inconsistentes: se esperaba NUMBER se ha obtenido BINARY ADVERTENCIA: /pages/common/cambiarFoto.xhtml @ 34,74 fileUploadListener = "# {barraBB.actualizarFoto}": org.hibernate.exception.SQLGrammarException: native Bulk-Manipulationsabfrage konnte nicht ausgeführt werden javax.el.ELException:/pages/common/cambiarFoto.xhtml @ 34,74 fileUploadListener = "# {barraBB.actualizarFoto} ": org.hibernate.exception.SQLGrammarException: konnte die native Bulk-Manipulationsabfrage unter com.sun.faces.facelets.el.TagMethodExpression.invoke (TagMethodExpression.java:111) nicht ausführen bei org.primefaces. component.fileupload.FileUpload.broadcast (FileUpload.java:310) bei javax.faces.component.UIViewRoot.broadcastEvents (UIViewRoot.java:755) bei javax.faces.component.UIViewRoot.processDecodes (UIViewRoot.java:931) bei com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute (ApplyRequestValuesPhase.java:78) bei com.sun.faces.lifecycle.Phase.doPhase (Phase.java:101) bei com.sun.faces.lifecycle. LifecycleImpl.execute (LifecycleImpl.java:198) bei javax.faces.webapp.FacesServlet.service (FacesServlet.java:646)
Warum rufen Sie toString auf Ihrem Blob? – Andreas