休眠 p6spy 问题
我试图了解 hibernate 在幕后所做的事情,并且我使用 p6spy 作为 mysql jdbc 驱动程序的代理,这样我就可以看到数据库真正发生了什么。然而,我对 p6spy 的输出有点困惑 - 感谢任何光线!
问题是这样的。我正在创建 Test1 类的两个新对象,即 test1a 和 test1b。我的日志中的输出如下:
Hibernate:
/* insert com.play.hibernate1.Test1
*/ insert
into
Test1
(name, value, id)
values
(?, ?, ?)
1274973057265|1|1|batch|/* insert com.play.hibernate1.Test1 */ insert into Test1 (name, value, id) values (?, ?, ?)|/* insert com.play.hibernate1.Test1 */ insert into Test1 (name, value, id) values ('Test 1', 10, 5)
Hibernate:
/* insert com.play.hibernate1.Test1
*/ insert
into
Test1
(name, value, id)
values
(?, ?, ?)
1274973057265|0|1|batch|/* insert com.play.hibernate1.Test1 */ insert into Test1 (name, value, id) values (?, ?, ?)|/* insert com.play.hibernate1.Test1 */ insert into Test1 (name, value, id) values ('Test 2', 20, 6)
1274973057267|2|1|statement|/* insert com.play.hibernate1.Test1 */ insert into Test1 (name, value, id) values (?, ?, ?)|/* insert com.play.hibernate1.Test1 */ insert into Test1 (name, value, id) values ('Test 2', 20, 6)
1274973057268|0|1|commit||
我可以看到两个“batch”语句,大概来自对 jdbc addBatch api 的调用,但是“1274973057267|2|1|statement”在那里做什么?看起来第二次插入正在重复,但我知道事实并非如此,否则我会在数据库中看到 3 行而不是两行,或者至少会出现错误。
为什么我看到第二个插入语句重复出现?
如果我在我的spy.properties中排除“batch”,我只会看到这个奇怪的流氓行。
感谢您的任何启发!
I'm trying to get to grips with what hibernate is doing under the hood, and I'm using p6spy as a proxy for the mysql jdbc driver so I can see what's really going to the database. I'm a little confused by the output from p6spy however - grateful for any light!
The problem is this. I'm creating two new objects of class Test1, namely test1a and test1b. The output in my logs is as follows:
Hibernate:
/* insert com.play.hibernate1.Test1
*/ insert
into
Test1
(name, value, id)
values
(?, ?, ?)
1274973057265|1|1|batch|/* insert com.play.hibernate1.Test1 */ insert into Test1 (name, value, id) values (?, ?, ?)|/* insert com.play.hibernate1.Test1 */ insert into Test1 (name, value, id) values ('Test 1', 10, 5)
Hibernate:
/* insert com.play.hibernate1.Test1
*/ insert
into
Test1
(name, value, id)
values
(?, ?, ?)
1274973057265|0|1|batch|/* insert com.play.hibernate1.Test1 */ insert into Test1 (name, value, id) values (?, ?, ?)|/* insert com.play.hibernate1.Test1 */ insert into Test1 (name, value, id) values ('Test 2', 20, 6)
1274973057267|2|1|statement|/* insert com.play.hibernate1.Test1 */ insert into Test1 (name, value, id) values (?, ?, ?)|/* insert com.play.hibernate1.Test1 */ insert into Test1 (name, value, id) values ('Test 2', 20, 6)
1274973057268|0|1|commit||
I can see two 'batch' statements, presumably from calls to the jdbc addBatch api, but what is that '1274973057267|2|1|statement' doing there? It LOOKS like the second insert is getting repeated, but I know it's not or I would see 3 rows in my db and not two, or at least an error.
Why I am I seeing the second insert statement repeated?
If I exclude 'batch' in my spy.properties, I ONLY see this weird, rogue line.
Thanks for any illumination!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
啊 - 我看到了这个问题,这似乎是由于我不得不说 p6spy 中的一个相当令人惊讶的设计决定造成的。
显然,对于批处理语句,决定在将语句添加到批处理时记录语句,然后显示批处理实际执行时执行的最后一条语句!一旦您知道该工具的作用,我想您就可以理解为什么它在那里,但它完全令人困惑且违反直觉,除非您碰巧读过这里的线程:
http://sourceforge.net/projects/p6spy/forums/forum/166969/topic/666877
Ah - I see the problem, which appears to be due to what I have to say is a rather surprising design decision in p6spy.
Apparently for batched statements, the decision was made to log statements as they are added to the batch, and then show the LAST statement executed when the batch is actually executed! Once you know that's what the tool does, I guess you can understand why it's there, but it's completely confusing and counter-intuitive unless you happen to have read the thread here:
http://sourceforge.net/projects/p6spy/forums/forum/166969/topic/666877
在
spy.properties
文件中,excludecategories
默认属性为[info,debug,result,batch]
,您可以排除
batch
类别,然后您将得到您想要的。In
spy.properties
file, the default property ofexcludecategories
is[info,debug,result,batch]
,You can exclude the
batch
category, then you will get what you want.它的尾部 (513) 看起来像时间戳的一部分
The tail end of it (513) looks like part of the timestamp