我有一个Actor(Play Framework,Java),用于定期进行一些数据库数据导入.这个actor调用各种其他类进行导入,持久化等.我当前的问题是我无法弄清楚生成SQL异常的确切行号和文件.例如,我得到这样的错误:[info] applicati...
我有一个Actor(Play Framework,Java),用于定期进行一些数据库数据导入.这个actor调用各种其他类进行导入,持久化等.我当前的问题是我无法弄清楚生成SQL异常的确切行号和文件.例如,我得到这样的错误:
[info] application - javax.persistence.PersistenceException: ERROR executing DML bindLog[] error[ERROR: null value in column "email" violates not-null constraint\n Detail: Failing row contains (266, null, null, null).]
[info] application - Starting persisting of customer id 29917837
[error] o.j.StatementLogger - insert into emails (email, domain, user_id) values (null,null,null);
throws exception: org.postgresql.util.PSQLException: ERROR: null value in column "email" violates not-null constraint
Detail: Failing row contains (268, null, null, null).
org.postgresql.util.PSQLException: ERROR: null value in column "email" violates not-null constraint
Detail: Failing row contains (268, null, null, null).
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2182)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1911)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:173)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:645)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:495)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:441)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
当然,我可以查看错误消息,看看某处某处正试图保留我的电子邮件模型而不填充它.现在代码库非常小(约200-300行),我可以非常准确地猜测它来自哪里.但框架是否也应该报告行号?或者这可能是演员在使用时发生的事情,因为他们在某种程度上,某种程度上,在系统之外都是如此?
解决方法:
您正在使用一个框架,使用反射执行它的查询,这使得调试非常困难.我不知道你正在使用的具体框架,但很可能它的配置可以设置为使调试这类事情更容易.
如果没有,或者它是您自己的使用反射的代码,您可以捕获异常,将其包装,并从“外部”代码(即执行反射操作的代码)中重新抛出它.这将为您提供额外的堆栈跟踪,其中包含代码中的确切位置.
例如,您可以使用包装器代码执行此操作:
try {
this.custPersister.persist(customer);
} catch (Exception e) {
throw new Exception(e);
}
只需确保在外部代码中的适当位置捕获此异常,并记录堆栈跟踪.
本文标题为:java – 找出生成SQL异常的代码行
- Java递归实现评论多级回复功能 2023-02-05
- SpringBoot图文并茂详解如何引入mybatis与连接Mysql数据库 2023-03-07
- SpringBoot热部署设置方法详解 2023-06-23
- SpringBoot项目使用mybatis-plus代码生成的实例详解 2023-06-11
- MybatisPlus保存、读取MySQL中的json字段失败问题及解决 2023-02-19
- java – 用spring数据更新对象mongodb和kotlin不能正常工作 2023-11-02
- 深入理解Java虚拟机——垃圾收集器与内存分配策略(读书笔记) 2023-09-01
- Java实现经典游戏黄金矿工的示例代码 2022-11-01
- CentOS 6.4出现Disk sda contains BIOS RAID metadata解决方法 jajavaja的专栏 2023-08-31
- java实现简单的学生管理系统 2022-11-01