Spring 无法查看由hibernate架构导出(H2数据库)生成的表

Spring 无法查看由hibernate架构导出(H2数据库)生成的表,spring,h2,spring-boot,Spring,H2,Spring Boot,我正在尝试使用SpringBoot(v1.1.1.RELEASE)和H2数据库运行一个小应用程序。在日志记录中,我看到ddl已正确生成,但在H2数据库中找不到表 我手动将ddl复制到一个db可视化工具中,sql就可以了。我不知道我错过了什么。当执行代码时,JPA持久层似乎正确地存储了数据,因为我得到了生成的ID,等等。。我认为我在JDBCURL中犯了一个错误,但它们都指向同一个基于文件的H2数据库。但这个数据库似乎没有数据 JPA对象 JPARepository @Repository pub

我正在尝试使用SpringBoot(v1.1.1.RELEASE)和H2数据库运行一个小应用程序。在日志记录中,我看到ddl已正确生成,但在H2数据库中找不到表

我手动将ddl复制到一个db可视化工具中,sql就可以了。我不知道我错过了什么。当执行代码时,JPA持久层似乎正确地存储了数据,因为我得到了生成的ID,等等。。我认为我在JDBCURL中犯了一个错误,但它们都指向同一个基于文件的H2数据库。但这个数据库似乎没有数据

JPA对象

JPARepository

@Repository
public interface RawDataRepository extends JpaRepository<RawData, Long> {

}
日志信息

org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
Hibernate: drop table PUBLIC.rawdata if exists
Hibernate: create table PUBLIC.rawdata (id bigint generated by default as identity, payload clob not null, primary key (id))
org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
测试代码

@Autowired
private RawDataRepository repository;

repository.saveAndFlush(new RawData("test"));
System.out.println(repository.count());

因此,保存一个JPA对象实际上似乎会持久化该对象(计数增加等),但数据和表结构不会出现在数据库中。我看到,在持久化对象时,修改的日期会更改数据库,但我似乎无法使用squirrel/dbvisualizer等查看数据。。任何提示或提示?

问题是,当应用程序关闭时,Hibernate将删除整个架构,因为您已经配置了
spring.jpa.Hibernate.ddl auto=create drop


如果您将配置更改为
spring.jpa.hibernate.ddl auto=create
,则不会在会话结束时删除模式,您将能够看到创建的表以及插入的任何数据

您可以使用
H2 Console
查看数据吗?只是尝试了一下,没有找到表,可能是我做了一些非常愚蠢的事情……当应用程序运行时,db插入是否不可见?我在代码中放置了断点来检查数据库的内容。因此,在插入检查结构和内容之后。数据在Hibernate会话关闭时提交到数据库,而不是在调用各种保存或更新方法时。我已经测试了“创建”。当我使用CTRL-C关闭我的Spring Boot应用程序时,应用程序被终止,两个文件仍然是devdb.h2.db和devdb.lock.db。这是否意味着当我关闭我的应用程序时,Hibernate会话没有正确关闭,数据也没有持久化?为了在应该的时候提交所有内容,我建议你应用事务边界(使用
@Transactional
)。@Marco你有没有发现问题的原因?
org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
Hibernate: drop table PUBLIC.rawdata if exists
Hibernate: create table PUBLIC.rawdata (id bigint generated by default as identity, payload clob not null, primary key (id))
org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
@Autowired
private RawDataRepository repository;

repository.saveAndFlush(new RawData("test"));
System.out.println(repository.count());