Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring boot应用程序,H2嵌入式数据库-但当应用程序关闭时,表将消失_Java_Spring_Hibernate_Spring Boot_H2 - Fatal编程技术网

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

Java Spring boot应用程序,H2嵌入式数据库-但当应用程序关闭时,表将消失,java,spring,hibernate,spring-boot,h2,Java,Spring,Hibernate,Spring Boot,H2,我的数据库属性文件是: 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

我的数据库属性文件是:

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,而是使用update,因为此代码当前处于变化中,我希望在发生更改时调整表。但这似乎不是问题所在,因为在app关闭时,表一直在消失


任何帮助都将不胜感激。

如果您希望spring boot捕获您的hibernate属性,您应该在它们前面加上
spring.jpa
,因此:

spring.jpa.hibernate.ddl-auto=update

否则,在我看来,spring将使用默认的
create-drop
选项处理内存中的H2数据库。

如果您希望spring引导捕获您的hibernate属性,您应该在它们前面加上
spring.jpa
,因此:

spring.jpa.hibernate.ddl-auto=update

否则,在我看来,spring将使用默认的
create-drop
选项处理内存中的H2数据库。

通过将以下行添加到应用程序。属性

spring.jpa.hibernate.ddl-auto=update

当应用程序退出时,Spring boot停止删除表。

通过将以下行添加到应用程序。属性

spring.jpa.hibernate.ddl-auto=update

当应用程序退出时,Spring boot停止删除表。

您是如何配置应用程序以使用database.properties的?您使用的是哪个版本的Spring Boot?您正在使用Spring Boot的DevTools吗?[最小、完整、可验证的示例](help/mcve)将使您的问题更容易回答我的应用程序上下文文件中有一个加载database.properties的PropertyPlaceHolderConfigure。然后在我的SessionFactoryBean中,我将hibernate属性设置为占位符值?您使用的是哪个版本的Spring Boot?您正在使用Spring Boot的DevTools吗?[最小、完整、可验证的示例](help/mcve)将使您的问题更容易回答我的应用程序上下文文件中有一个加载database.properties的PropertyPlaceHolderConfigure。然后在我的SessionFactoryBean中,我将hibernate属性设置为占位符值。我在所有database.properties hibernate条目的前面加上了“spring.jpa”,并更新了上下文文件以使用这些新值。但当我运行应用程序时,表仍然被删除。我还将我的选项从“hibernate.hbm2ddl.auto”更改为“hibernate.ddl auto”来处理上述内容,但这并没有改变行为。不幸的是,这并没有改变行为。我在所有database.properties hibernate条目的前面加上了“spring.jpa”,并更新了上下文文件以使用这些新值。但当我运行应用程序时,表仍然被删除。我还将我的选项从“hibernate.hbm2ddl.auto”更改为“hibernate.ddl auto”,以对上述内容进行处理,但这对行为没有影响。