How to restore sql query from ResultSet

Somewhere inside the JBoss in the sleep request, I get an error that leaves me with a ResultSet. This code is connected to a user data type.

It would be nice if I could just do rs.getStatement (). toString () and get it over with, but unfortunately it doesn't give anything about the sql statement that went into it.

I was thinking of doing something with ((PreparedStatement) rs.getStatement ()). getMetaData ().

I really wanted the hibernation mode to be a little more informative when it encountered errors. Does anyone have a good solution to help identify which table and which column were used when an exception occurred?

+4
source share
3 answers

Just enable SQL logging in the Hibernate configuration properties by setting the hibernate.show_sql property to true.

This is more reliable than checking metadata for results, since the where clause is not available.

+2
source

One way to debug Hibernate is to enable verbose logging.

For example, you can write all SQL statements as they run, by enabling logging for org.hibernate.SQL . From here you can narrow down the last expression executed before your exception.

Documentation can be found here .

+1
source

Getting MetaData for ResultSet will not allow you to get the information that has been transmitted. In Hibernate, you can output statements to a log file.

Most JDBC drivers allow you to configure tracing so that you can debug.

0
source

Source: https://habr.com/ru/post/1315572/


All Articles