What is the best practice of using large objects in PostgreSQL?
I meet problems when using the following approach:
http://www.hibernate.org/73.html
With Firebird it worked for me OK.
============
Hibernate version:
3.0.4
Mapping documents:
I have a byte[] property - history and map it into BinaryBlobType:
Code:
<property name="history" column="history" type="BinaryBlobType"/>
In DB table it maps to OID - PK to large object.
The BinaryBlobType code is:Code:
public class BinaryBlobType implements UserType {
public int[] sqlTypes() {
return new int[] {Types.BLOB};
}
public Class returnedClass() {
return byte[].class;
}
.........
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws
HibernateException, SQLException {
return rs.getBytes(names[0]);
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws
HibernateException, SQLException {
st.setBytes(index, (byte[]) value);
}
.......
}
Code between sessionFactory.openSession() and session.close():
I'm using Spring Framework 1.2 anf subclassing HibernateDaoSupport for Hibernate data access objects.
Full stack trace of any exception that occurs:
javax.servlet.ServletException: Bad SQL grammar [] in task 'HibernateTransactionManager'; nested exception is java.sql.SQLException: ERROR: column "history" is of type oid but expression is of type bytea
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:241)
com.volin.filters.CompressionFilter.doFilter(CompressionFilter.java:85)
root cause
org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [] in task 'HibernateTransactionManager'; nested exception is java.sql.SQLException: ERROR: column "history" is of type oid but expression is of type bytea
org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:223)
org.springframework.orm.hibernate3.HibernateTransactionManager.convertJdbcAccessException(HibernateTransactionManager.java:600)
org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:496)
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:401)
org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:260)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:67)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
Name and version of the database you are using:
PostgreSQL 8.0.3