Fix error handling in QueriesResourceService

When there was a problem running the query in QueriesResourceService,
the method was supposed to recover and write information about the error
on the database.

Unfortunately, postgres was aborting the transaction at this point, so
the data saved before the error would be lost and the error logging
information would not get written. This commit fixes this problem with a
SAVEPOINT, which allows the transaction to be recovered.

Also improved some (log4j) logging statements.