Hibernate H2 数据库相对路径

Hibernate H2 database relative path

我有一个 H2 数据库文件调用 "test.db"。该文件位于我的应用程序中 目录:"myApp/resources/test.db"。 我无法在 me.So 上使用它,引用相对路径的正确方法是什么。

这是我的hibernate.cfg.xml的配置。

 <property name="connection.driver_class">org.h2.Driver</property>
        <property name="connection.url">jdbc:h2:file:/test</property>
        <property name="connection.username">test</property>
        <property name="connection.password">1234</property>


        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.H2Dialect</property>

出现的错误是:

Caused by: org.h2.jdbc.JdbcSQLException: A file path that is implicitly relative to the current working directory is not allowed in the database URL "jdbc:h2:file:/test2". Use an absolute path, ~/name, ./name, or the baseDir setting instead. [90011-191]

您应该将 URL 写为显式相对路径: <property name="connection.url">jdbc:h2:file:./test</property>