SQL Error: 0, SQLState: 25P02 (current transaction is aborted) with no transaction
I have encuntered the same error (SQL Error: 0, SQLState: 25P02). After seeing the whole log, I saw that there was a previous error that triggered this one and in my case the error is was because there were no grant on the tables. Being in the same transaction the exception is raised
randomVariable
Updated on June 04, 2022Comments
-
randomVariable over 1 year
I am using JPA with Hibernate to run the following method. The thing is, when FETCH_MAIL_VERDICTS (a dynamically created select statement string) is wrong and gives an SQLGrammarException, other unrelated queries (created from unrelated EntityManagers) also stops responding because of "SQL Error: 0, SQLState: 25P02" (Postgres) error. Google says this is caused by not rolling back an erroneous query, but there is no transaction here. I also tried rolling back in the catch statement just to be safe, but the problem still occurs.
Thank you
public static List<VeMailRecord> getMailVerdicts(HttpServletRequest request, String query, String limit, boolean includeBodies, boolean includeAttachments) { String FETCH_MAIL_VERDICTS = "SELECT * FROM ve_mail_records "; if(query != null && query.length() > 0) FETCH_MAIL_VERDICTS += "where origin_id = -1 and " + query; else FETCH_MAIL_VERDICTS += "where origin_id = -1"; if(!FETCH_MAIL_VERDICTS.contains("order by")) //Default order FETCH_MAIL_VERDICTS += " order by receive_time desc "; int limitInt, limitConfig; try{ limitInt = Integer.parseInt(limit); limitConfig = Integer.parseInt(Config.getProperty("analyst.verdict.limit")); if(limitInt > limitConfig) limitInt = limitConfig; FETCH_MAIL_VERDICTS += " LIMIT " + limitInt + ";"; } catch (NumberFormatException e) { FETCH_MAIL_VERDICTS += " LIMIT " + Config.getProperty("analyst.verdict.limit") + ";"; } EntityManager em = entityManagerFactory.createEntityManager(); List<VeMailRecord> mailList = null; try{ mailList = em.createNativeQuery(FETCH_MAIL_VERDICTS, VeMailRecord.class).getResultList(); if(mailList == null) mailList = new ArrayList<VeMailRecord>();//Dummy array list to discriminate //Get attachments of each e-mail //VeMailRecord lazy fetches attachments . Force loading attachments if(includeAttachments){ for(VeMailRecord mail : mailList) { for(AttachmentContainer attachment : mail.getAttachmentList()) { attachment.getFilename(); } } } //Remove Bodies if(includeBodies){ for(VeMailRecord mail : mailList) { mail.setBody(""); } } } catch (Exception e) { logger.error("Error while querying in function 'getMailVerdicts'.", e); mailList = null; } finally { em.close(); } return mailList; }