HSQLDB 约束违规 & HSQLDB 内存设置的 SQL 查询日志
我们有一个设置,使用嵌入式 HSQLDB 来支持 Java 中的 Hibernate/JPA 单元测试,并且我们使用内存数据库模式,因为我们只是希望在测试运行后丢弃数据库。我的问题是,其中一项测试由于违反约束而失败,并且 HSQLDB 将该列列为 SYS_CT_286,日志中显示的查询是准备好的语句,我无法看到实际参数值是什么(它们被替换为'?')。我的问题是:
1- 有没有办法可以看到实际执行的 SQL? (例如mysql查询日志?)。
2- SYS_CT_286 到底是什么?它不是我的列之一,它是生成的列吗?有什么明显的问题可能存在吗?
谢谢。
We have a setup where we are using an embedded HSQLDB for backing Hibernate/JPA unit tests in java, and we are using the in-memory database mode since we simply want the database thrown away after the test run. My problem is that one of the tests is failing due to a constraint violation and HSQLDB lists the column as SYS_CT_286, and the query that appears in the log is the prepared statement where I cant see what the actual parameter values are (they are replaced by '?'). My questions are:
1- Is there a way in which I can see the actual SQL being executed? (like the mysql query log for example?).
2- What exactly is SYS_CT_286? it is not one of my columns, is it a generated column? is there something obvious that may be wrong with it?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定 HSQLDB 是否允许记录正在执行的 SQL 语句(如 select),但您可以使用代理 JDBC 驱动程序,如 P6Spy 为此(已在此答案中提到)。
这是一个约束(我敢打赌这是一个唯一的约束)。
I'm not sure HSQLDB allows to log the SQL statements (like select) being executed but you can use a proxy JDBC driver like P6Spy for this (already mentioned in this answer).
This is a constraint (and I would bet on a unique constraint).
HSQLDB 保留重做日志,这对于调试已运行的 sql 可能很有用,但我不确定它是否对内存数据库执行此操作。如果您临时将数据库更改为名为 test 的基于文件的数据库,则重做日志应命名为 test.log,但它会在干净关闭后消失。
SYS_CT_286 很可能是具有系统生成名称的约束。同样,如果您创建一个基于文件的数据库,您也许能够查看它并找出它的约束。如果这是您定义的约束,您甚至可以更改映射,以便它获得一个合理的名称。我知道无论如何你都可以通过外键约束来做到这一点。
HSQLDB keeps a redo log, which might be useful for debugging what sql has been run, but I'm not sure if it does this for an in-memory db. If you change your db temporarily to a file-based db named test, the redo log should be named test.log, but it disappears on a clean shutdown.
SYS_CT_286 is most likely a constraint with a system-generated name. Again, if you make a file-based DB, you might be able to look at it and find out what it's a constraint for. And if it's a constraint you're defining, you might even be able to change your mapping so it gets a sensible name. I know you can do this with foreign key constraints anyway.