-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: PostgreSQL Dialect: what is the best practice of using blob?
PostPosted: Sun Jul 03, 2005 2:20 pm 
Beginner
Beginner

Joined: Mon Jan 05, 2004 12:48 pm
Posts: 31
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 03, 2005 4:34 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
If culumn is type of "bytea" for then use
"st.setBytes(index, (byte[]) value);".
If culumn is type of "OID" for then use:
"st.setBlob(index, Hibernate.createBlob((byte[]) value));".

http://jdbc.postgresql.org/documentatio ... -data.html


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 03, 2005 4:47 pm 
Beginner
Beginner

Joined: Mon Jan 05, 2004 12:48 pm
Posts: 31
Thank you very much ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.