Question

When an org.hibernate.JDBCException occurrs (or a Subtype of this Exception) the sql statement is not visible in the Stacktrace.

For Example if i execute the following SQL statement with hibernate (on an Oracle DB which does not have a table or view 'nonexsiting'):

session.createSQLQuery("select * from nonexisting").list();

i get the following stacktrace:

org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
    ...
Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: Table or view does not exist
    ...

The SQL statement is not shown in the stacktrace, however the Exception object has the information stored and can be accessed by exception.getSQL(). It would extremely speed up debugging if this information would be available in the stacktrace too.

Anybody an idea why this information is not available in the stacktrace? Or how to enable the output of this information in the stacktrace?

By the way the hibernate version i used for this example is 3.3.1

Was it helpful?

Solution

Because that's not how it has been implemented. See HB-1055.

Spring and the classes implementing PersistenceExceptionTranslator might provide something closer to your expectations.

OTHER TIPS

I assume that it could be a security issue. If you add the sql statement to the stack trace, it might be published to a user and so give him information about your table names and columns. If your application is vulnerable to sql injection, this would be a really big benefit for intruders.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top