hsqldb ignores first insert operation on table at server (server needs to be “warmed up”?)

安稳与你 提交于 2019-12-10 12:04:37

问题


We're having a very curious problem with hsqldb. We are running some tests which works perfectly well on MySQL, but we have recently switched to hsqldb for our unit tests. In doing so, we noticed that some of our tests started to fail. One of the tests inserts three records A, B and C, and attempts to retrieve the first two, A and B. However, only B is returned the first time we run the test on a freshly configured (empty) database. However, if we repeat the test on the same database, both A' and B' are returned (before you ask, yes A, B and C are different from A', B' and C').

We have attempted to force the database to persist the records, and we have inserted delays. Nothing seems to help, except "warming up the database" with a single insert. If we check the hsqldb logs afterwards they contain all the insert statements, even the ones we are unable to retrieve using SELECT in our first run on the database.

Has anybody ever experienced issues with hsqldb needing to be "warmed up" with a dummy insert statement? If we perform an insert statement with garbage before running our tests they will also complete successfully.

We have tested on hsqldb 2.0.0 and 2.1.0. Both versions yield the same result.


回答1:


I have never used hsqldb but have you tried INSERT INTO ...; COMMIT; and then run SELECT ..?

It's not unreasonable for a database operation (INSERT, UPDATE or DELETE) to be delayed. It probably shouldn't happen when database is not under heavy load but you can't count on it.




回答2:


The real answer is given by the OP in one of the comments. HSQLDB does not ignore the first insert. By default, HSQLDB and MySQL use 0 and 1 respectively for the first autoincrement value generated for an identity column in the table. The OP's query assumed the first value was the MySQL value (1).

With HSQLDB, GENERATED BY DEFAULT AS IDENTITY START WITH 1 can be used for the definition of an autoincrement column to match the MySQL default value.



来源:https://stackoverflow.com/questions/5456742/hsqldb-ignores-first-insert-operation-on-table-at-server-server-needs-to-be-wa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!