Spring-boot应用程序,H2嵌入式数据库 - 但是当应用程序关闭时表格会消失

问题描述 投票:0回答:2

我的database.properties文件是:

datasource.driver=org.h2.Driver
datasource.url=jdbc:h2:file:./test_database/comixed_db;create=true
datasource.username=sa
datasource.password=

hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
hibernate.format_sql=true
hibernate.batch.size=20
hibernate.current.session.context.class=org.springframework.orm.hibernate5.SpringSessionContext
hibernate.generate_statistics=false
hibernate.enable_lazy_load_no_trans=false

当我的应用程序启动时我看到我能够通过使用h2.bat工具,并在从Web浏览器的数据库偷看看表。然而,当我关闭应用程序,然后返回到数据库与h2.bat工具的桌子全都不见了!

我在使用hibernate配置时做错了什么?我没有使用create-drop但是更新,因为此代码目前处于不稳定状态,我希望在发生更改时调整表。但这似乎不是问题,因为在应用程序关闭时,表格会不断消失。

任何帮助,将不胜感激。

java spring hibernate spring-boot h2
2个回答
1
投票

如果你想春天开机赶上你的Hibernate属性,你应该spring.jpa前缀他们,所以:

spring.jpa.hibernate.ddl-auto=update

否则,在我看来就是这种情况,spring将使用默认的create-drop选项,因为它正在处理H2内存数据库。


1
投票

通过将以下行添加到applications.properties:

spring.jpa.hibernate.ddl-auto=update

春季启动停止删除表的应用程序退出时。

© www.soinside.com 2019 - 2024. All rights reserved.