Hi all, I’m trying to make an application that upload a file from my hard disk to a data base... I’m using SQL server 2000 and the data type of the field where I’m trying to save the file content is “image”. In mapping file the data type is “blob”, here is a mapping excerpt:
<property
name="deDocAttached"
type="blob"
column=" deDocAttached"
not-null="true" />
and here is the source code excerpt of my application:
try
{
sesion = sesionPersistenciaFactory.crearSesionPersistenciaTx();
AnexosODSActionForm odsBean = (AnexosODSActionForm) form;
DocumentoAnexoDAO daoDocAnex = DocumentoAnexoDAOImpl.getInstance();
DocmtoAnexo docmtoAnexo = new DocmtoAnexoImpl();
FormFile formFile = odsBean.getAnexoDesdeSA();
byte[] fileData = formFile.getFileData();
Blob blogObj = net.sf.hibernate.Hibernate.createBlob(formFile.getInputStream());
docmtoAnexo.setDeContenidoDocmtoAnexo(blogObj);
sesion.save(docmtoAnexo);
LOG.debug("Agregando ods-documento anexo: " + odsDocmtoAnexo);
sesion.save(odsDocmtoAnexo);
LOG.debug("Anexo agregado!");
sesion.commitAndClose();
sesion = null;
My problem is:
After I do the commit, the data base looks frozen and the record is never saved. But I don’t see any error in log.
2005-01-21 17:31:01,125 DEBUG [net.sf.hibernate.impl.Printer] listing entities:
2005-01-21 17:31:01,125 DEBUG [net.sf.hibernate.impl.Printer] com.procedatos.clinycas.ods.impl.OrdenServicioDocmtoAnexoImpl{documentoAnexo=null, ordenServicio=null, idOrdenServicioDocmtoAnexoPK=OrdenServicioDocmtoAnexoPKImpl{idVersion=1, idDocmtoAnexo=9, idOrdenServicio=16}}
2005-01-21 17:31:01,125 DEBUG [net.sf.hibernate.impl.Printer] com.procedatos.clinycas.ods.impl.TipoDocmtoAnexoImpl{deDpi=200, deTipoDocmtoAnexo=Informe médico, exámen, carta, presupuesto, deColor=Blanco y negro (1 bit), deMaxPermitido=1, documentosAnexos=uninitialized, idTipoDocmtoAnexo=3, inTransparente=false}
2005-01-21 17:31:01,125 DEBUG [net.sf.hibernate.impl.Printer] com.procedatos.clinycas.ods.impl.DocmtoAnexoImpl{deContenidoDocmtoAnexo=net.sf.hibernate.lob.BlobImpl@1ab5e85, tipoDocumentoAnexo=TipoDocmtoAnexoImpl#3, idDocmtoAnexo=9, ordenesServicios=null, deDocmtoAnexo=imagen anexada desde la web}
2005-01-21 17:31:01,125 DEBUG [net.sf.hibernate.impl.SessionImpl] executing flush
2005-01-21 17:31:01,125 DEBUG [net.sf.hibernate.persister.EntityPersister] Inserting entity: [com.procedatos.clinycas.ods.impl.DocmtoAnexoImpl#9]
2005-01-21 17:31:01,125 DEBUG [net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
2005-01-21 17:31:01,125 DEBUG [net.sf.hibernate.SQL] insert into DocmtoAnexo (deContenidoDocmtoAnexo, deDocmtoAnexo, idTipoDocmtoAnexo, idDocmtoAnexo) values (?, ?, ?, ?)
2005-01-21 17:31:01,125 DEBUG [net.sf.hibernate.impl.BatcherImpl] preparing statement
2005-01-21 17:31:01,125 DEBUG [net.sf.hibernate.persister.EntityPersister] Dehydrating entity: [com.procedatos.clinycas.ods.impl.DocmtoAnexoImpl#9]
2005-01-21 17:31:01,125 DEBUG [net.sf.hibernate.type.BlobType] binding 'net.sf.hibernate.lob.BlobImpl@1ab5e85' to parameter: 1
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.type.StringType] binding 'imagen anexada desde la web' to parameter: 2
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.type.IntegerType] binding '3' to parameter: 3
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.type.IntegerType] binding '9' to parameter: 4
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.persister.EntityPersister] Inserting entity: [com.procedatos.clinycas.ods.impl.OrdenServicioDocmtoAnexoImpl#com.procedatos.clinycas.ods.impl.OrdenServicioDocmtoAnexoPKImpl@f30862[idOrdenServicio=16,idVersion=1,idDocmtoAnexo=9]]
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.impl.BatcherImpl] closing statement
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.SQL] insert into OrdenServicioDocmtoAnexo (idOrdenServicio, idVersion, idDocmtoAnexo) values (?, ?, ?)
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.impl.BatcherImpl] preparing statement
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.persister.EntityPersister] Dehydrating entity: [com.procedatos.clinycas.ods.impl.OrdenServicioDocmtoAnexoImpl#com.procedatos.clinycas.ods.impl.OrdenServicioDocmtoAnexoPKImpl@f30862[idOrdenServicio=16,idVersion=1,idDocmtoAnexo=9]]
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.type.IntegerType] binding '16' to parameter: 1
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.type.IntegerType] binding '1' to parameter: 2
2005-01-21 17:31:01,141 DEBUG [net.sf.hibernate.type.IntegerType] binding '9' to parameter: 3
2005-01-21 17:31:01,156 DEBUG [net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
2005-01-21 17:31:01,156 DEBUG [net.sf.hibernate.impl.BatcherImpl] closing statement
2005-01-21 17:31:01,156 DEBUG [net.sf.hibernate.impl.SessionImpl] post flush
2005-01-21 17:31:01,156 DEBUG [net.sf.hibernate.impl.SessionImpl] closing session
2005-01-21 17:31:01,156 DEBUG [net.sf.hibernate.impl.SessionImpl] disconnecting session
2005-01-21 17:31:01,156 DEBUG [org.apache.struts.tiles.TilesRequestProcessor] processForwardConfig(/ods/mostrarAnexos.jsp, false)
2005-01-21 17:31:01,156 DEBUG [org.apache.struts.tiles.TilesRequestProcessor] '/ods/mostrarAnexos.jsp' - processed as uri
2005-01-21 17:31:01,156 DEBUG [org.apache.struts.action.RequestProcessor] processForwardConfig(ForwardConfig[name=mostrarAnexos,path=/ods/mostrarAnexos.jsp,redirect=false,contextRelative=false])
2005-01-21 17:31:01,172 DEBUG [com.procedatos.clinycas.web.filtros.GZIPResponseStreamImpl] Comprimiendo ...
2005-01-21 17:31:01,172 DEBUG [com.procedatos.clinycas.web.filtros.HTTPLogFilter]
*** INICIO de /clinycas/ods/mostrarAnexosODSSubmit.do ***************************************
Usuario : 13102598
# Parametros :
# Attributos de Sesion : tiposDocmtoAnexo([com.procedatos.clinycas.ods.impl.TipoDocmtoAnexoImpl@833a2e[idTipoDocmtoAnexo=1], com.procedatos.clinycas.ods.impl.TipoDocmtoAnexoImpl@160ce61[idTipoDocmtoAnexo=2], com.procedatos.clinycas.ods.impl.TipoDocmtoAnexoImpl@8d63cf[idTipoDocmtoAnexo=3]]), anexosOdsFormBean(com.procedatos.clinycas.web.ods.docanex.AnexosODSActionForm@2437ef), org.apache.struts.action.LOCALE(es_VE),
*** FIN de /clinycas/ods/mostrarAnexosODSSubmit.do ***************************************
2005-01-21 17:31:02,453 DEBUG [net.sf.hibernate.impl.SessionImpl] running Session.finalize()
2005-01-21 17:31:02,453 WARN [net.sf.hibernate.impl.SessionImpl] afterTransactionCompletion() was never called
My questions is:
Does anybody know what’s wrong ??
Could I save a file in a data base using Hibernate ?? I said that because I did the same example using jdbc and it worked perfect.
As I said above, we are using SQL server 2000, Hibernate 2.1.6 as a service in JBoss 3.2.2
Thanks in advance,
Alejandro.-
|