Hibernate H2 数据库相对路径

abd*_*mer 3 java hibernate h2

我有一个名为“test.db”的 H2 数据库文件。该文件位于我的应用程序目录中:“myApp/resources/test.db”。我无法为我解决这个问题。所以,引用相对路径的正确方法是什么。

这里是我的 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>
Run Code Online (Sandbox Code Playgroud)

发生的错误是:

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]
Run Code Online (Sandbox Code Playgroud)

Mat*_*ldi 5

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