我在将字节数组保存到我的 Informix 数据库时遇到了麻烦,我将向您展示我是如何尝试的:
在 Fichero.java 中,我有这个:
@Column(name="fichero", columnDefinition="blob")
private byte[] contenido;
我不得不这样做,因为我无法让 Informix+Hibernate 接受 @Lob 注释(是的,我尝试过扩展 Hibernate 的方言解决方法,但它对我不起作用)
然后我读取一个文件并以这种方式将其转换为字节数组:FileManager.java
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;
}
接下来我尝试将其保存到我的数据库中:FicheroDAO.java
public void save(Object object) {
getHibernateTemplate().save(object);
}
对象是我的 Fichero 对象。
Buuuuut,我得到以下异常。
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)
异常中的下一行指向 FicheroDAO.java 文件以及它尝试保存对象的行号...
有任何想法吗?