The roots of the problem are in the Hibernate database dialects.
Some of the dialects does not implement proper Exception translation.

Implement custom dialect for Hibernate which would translate Exceptions with 
"does not exists"  in description to SQLGrammarException.

The code below shows the implementation for PostgreSQL 7.3 dialect



  | package org.hibernate.dialect;
  | 
  | 
  | import org.hibernate.exception.*;
  | 
  | public class PostgreSQLDialectWithExceptionTranslator extends 
PostgreSQLDialect {
  | 
  |     public PostgreSQLDialectWithExceptionTranslator(){
  |             super();
  |     }
  | 
  |     public SQLExceptionConverter buildSQLExceptionConverter() {
  | 
  |             ClassLoader ldr = this.getClass().getClassLoader();
  |             
  |             Class clazz;
  |             try{
  |                     clazz = 
ldr.loadClass("org.hibernate.dialect.PostgresqlExceptionConverter");
  |             
  |             
  |                     PostgresqlExceptionConverter converter = 
(PostgresqlExceptionConverter)clazz.newInstance();
  |                     
  |                     return (SQLExceptionConverter)converter;
  |             }
  |             catch (Exception e){
  |                     e.printStackTrace();
  |             }
  |             
  |             return null;
  |     }
  | }
  | 


  | package org.hibernate.dialect;
  | 
  | import java.sql.SQLException;
  | 
  | import org.hibernate.JDBCException;
  | import org.hibernate.exception.ConstraintViolationException;
  | import org.hibernate.exception.GenericJDBCException;
  | import org.hibernate.exception.JDBCConnectionException;
  | import org.hibernate.exception.JDBCExceptionHelper;
  | import org.hibernate.exception.LockAcquisitionException;
  | import org.hibernate.exception.SQLExceptionConverter;
  | import org.hibernate.exception.SQLGrammarException;
  | import org.hibernate.exception.ViolatedConstraintNameExtracter;
  | 
  | public class PostgresqlExceptionConverter  implements SQLExceptionConverter 
{
  | 
  |     private ViolatedConstraintNameExtracter extracter;
  | 
  |     public PostgresqlExceptionConverter(){
  |             
  |     }
  |     
  |     public PostgresqlExceptionConverter(ViolatedConstraintNameExtracter 
extracter) {
  |             this.extracter = extracter;
  |     }
  | 
  |     
  |     
  |     public void setExtracter(ViolatedConstraintNameExtracter extracter) {
  |             this.extracter = extracter;
  |     }
  | 
  |     public JDBCException convert(SQLException sqlException, String message, 
String sql) {
  | 
  |             String errorMsg = sqlException.getMessage();
  |             if ( errorMsg.endsWith("does not exist\n")){
  |                     return new SQLGrammarException( message, sqlException, 
sql );
  |             }
  | 
  |             return handledNonSpecificException( sqlException, message, sql 
);
  |     }
  | 
  |     protected JDBCException handledNonSpecificException(SQLException 
sqlException, String message, String sql) {
  |             return new GenericJDBCException( message, sqlException, sql );
  |     }
  | }
  | 
  | 

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3927944#3927944

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3927944


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to