尝试启动使用embedded h2.db
文件的应用时,我的tomcat日志中出现以下错误:
Caused by: org.h2.jdbc.JdbcSQLException: The database is read only**; SQL statement:<br>
UPDATE DATABASECHANGELOGLOCK SET LOCKED = TRUE, LOCKEDBY = '192.168.122.1 (192.168.122.1)', LOCKGRANTED = '2017-10-19 17:06:08.499' WHERE ID = 1 AND LOCKED = FALSE [90097-175]<br>
at org.h2.message.DbException.getJdbcSQLException(DbException.java:332)
at org.h2.message.DbException.get(DbException.java:172)
at org.h2.message.DbException.get(DbException.java:149)
at org.h2.message.DbException.get(DbException.java:138)
at org.h2.engine.Database.checkWritingAllowed(Database.java:1784)
at org.h2.table.Table.checkWritingAllowed(Table.java:1082)
at org.h2.engine.User.hasRight(User.java:114)
at org.h2.engine.User.checkRight(User.java:100)
at org.h2.command.dml.Update.update(Update.java:87)
正如您所看到的,它无法运行update语句来锁定数据库。
进行问题排查:
1.我打开一个h2 shell运行并直接连接到h2 db:
sudo java -cp h2.jar org.h2.tools.Shell -url "jdbc:h2:file:/usr/share/tomcat/ellucianmobile/banner-mobileserver/banner-mobileserver-prodD" -driver "org.h2.Driver" -user "sa" -password ""
然后我列出了表格:
sql> SHOW TABLES;
TABLE_NAME | TABLE_SCHEMA
BUILDING_DOMAIN | PUBLIC
CALENDAR | PUBLIC
CAMPUS_DOMAIN | PUBLIC
CATEGORY | PUBLIC
CONFIGURATION_DOMAIN | PUBLIC
DATABASECHANGELOG | PUBLIC
DATABASECHANGELOGLOCK | PUBLIC
ENTRY_CACHE | PUBLIC
ENTRY_CACHE_LINK | PUBLIC
ENTRY_DOMAIN | PUBLIC
EVENT | PUBLIC
EVENT_CATEGORIES | PUBLIC
FEED_CACHE | PUBLIC
FEED_CACHE_LINK | PUBLIC
MS_DEVICE | PUBLIC
MS_DEVICEUSER | PUBLIC
MS_NMESSAGE | PUBLIC
MS_NOTIFICATION | PUBLIC
MS_NOT_DEL_REC_DOMAIN | PUBLIC
MS_NSTATUS | PUBLIC
MS_RECIPIENT | PUBLIC
MS_RECIPIENT_STATUSES | PUBLIC
NOTIFICATION_DELIVERY_DOMAIN | PUBLIC
NUMBERS_DOMAIN | PUBLIC
REGISTRATION_CART | PUBLIC
SYSTEM_DATA_DOMAIN | PUBLIC
(26 rows, 28 ms)
我可以从给定的表中选择行:
(如下所示,锁定设置为FALSE)
sql> SELECT * FROM DATABASECHANGELOGLOCK;
ID | LOCKED | LOCKGRANTED | LOCKEDBY
1 | FALSE | null | null
(1 row, 1 ms)
由于阅读工作,我试着写信给DB:
sql> UPDATE DATABASECHANGELOGLOCK SET LOCKED=FALSE, LOCKGRANTED=null, LOCKEDBY=null where ID=1;
Error: org.h2.jdbc.JdbcSQLException: The database is read only;
尝试运行UPDATE以获取锁定时,tomcat获得的错误。
默认情况下,我可以做些什么来使h2 db可用于读写?
答案 0 :(得分:0)
在运行Tomcat作为服务的Windows服务器上,我遇到了同样的问题。默认情况下,它以LOCAL_SERVICE帐户运行,该帐户没有对db文件夹的写权限。您可以通过为LOCAL_SERVICE帐户的db文件夹授予修改权限,或将服务帐户更改为LOCAL_SYSTEM来解决此问题。
答案 1 :(得分:0)
添加它对我有用
@Configuration
@EnableJpaRepositories
@EnableTransactionManagement
class ApplicationConfig {
}