Hi,
I have troubles saving a byte array to my Informix database, I'll show you how I'm trying:
In Fichero.java among other things I have this:
Code:
@Column(name="fichero", columnDefinition="blob")
private byte[] contenido;
I had to do that way because I can't get Informix+Hibernate to accept @Lob annotation (yes, I tried that extending Hibernate's dialect workaround but it doesn't work for me)
Then I read a file and convert it to a bytearray this way:
FileManager.java
Code:
private byte[] fromFile2ByteArray(String nombreFichero) throws FileNotFoundException, IOException{
File file = new File(nombreFichero);
InputStream is = new FileInputStream(file);
byte[] contenido = new byte[(int)file.length()];
is.read(contenido);
is.close();
return contenido;
}
And next I try to save it to my database using:
FicheroDAO.java
Code:
public void save(Object object) {
getHibernateTemplate().save(object);
}
where the
object is my Fichero object.
Buuuuut, I get the following exception.
Code:
Hibernate:
/* insert es.cosas.modelo.datos.dominio.fichero.Fichero
*/ insert
into
cosas_fichero
(fichero, idEnvio, nombrefichero, respuesta)
values
(?, ?, ?, ?)
WARN : org.hibernate.util.JDBCExceptionReporter - SQL Error: -841, SQLState: S0000
ERROR: org.hibernate.util.JDBCExceptionReporter - Name must start with a letter or '_' and contain letters, digits, or '_'.
22-jun-2012 9:25:32 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() para servlet Spring MVC Dispatcher Servlet lanzó excepción
java.sql.SQLException: Name must start with a letter or '_' and contain letters, digits, or '_'.
at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:379)
at com.informix.jdbc.IfxSqli.addException(IfxSqli.java:3109)
at com.informix.jdbc.IfxSqli.receiveError(IfxSqli.java:3419)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2282)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2202)
at com.informix.jdbc.IfxSqli.executeFastPath(IfxSqli.java:5475)
at com.informix.jdbc.IfxSqli.executeFastPath(IfxSqli.java:5400)
at com.informix.jdbc.IfxSmartBlob.IfxLoColInfo(IfxSmartBlob.java:306)
at com.informix.jdbc.IfxSmBlob.createSmartLob(IfxSmBlob.java:751)
at com.informix.jdbc.IfxSmBlob.createBlobOnServer(IfxSmBlob.java:497)
at com.informix.jdbc.IfxResultSet.executeUpdate(IfxResultSet.java:301)
at com.informix.jdbc.IfxStatement.executeUpdateImpl(IfxStatement.java:885)
at com.informix.jdbc.IfxPreparedStatement.executeUpdate(IfxPreparedStatement.java:279)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:57)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2329)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2836)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:267)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:686)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:683)
The next line in the exception points to FicheroDAO.java file and the line number where it tries to save the object...
Any ideas?