EntityManager does not write to database

喜你入骨 提交于 2019-11-27 23:18:33

Adding to the good answer by axtavt and clarifying how your sleep(1000) worked: For development situations where you want absolutely synchronous persistence, turn off the default write_delay.

 <property name="hibernate.connection.url" 
      value="jdbc:hsqldb:file:data/db/db;shutdown=true;hsqldb.write_delay_millis=0"/>             

This means every statement is written to disk before the result is returned to the caller. Naturally, in normal operation, you can increase this value. The default is 500 ms, which needs the sleep(1000). The information given is for HSQLDB version 2.2.x.

You need to add shutdown=true to the database URL (or issue an explict SHUTDOWN command) in order to correctly shut down an in-process HSQLDB database:

<property name="hibernate.connection.url" 
     value="jdbc:hsqldb:file:data/db/db;shutdown=true" />             

See also:

Hope this helps someone. The suggestion to set the write delay to 0 ms works, but it does not work from the url unless you're creating a new db. To have it apply, run it in a script while connected to the database using the sql statement below:

set files write delay false

So for example, you can run it using the sqltool.jar like so:

java -jar /path/to/sqltool.jar -sql "set files write delay false;" --inlinerc=<rc spec here>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!