spring - HQSLDB——即使文件有内容,基于文件的数据库还是空的?为什么?

标签 spring hsqldb

各位,

我的问题

为什么我预先填充了架构和数据的 HSQLDB 基于文件的数据库在稍后连接到它时没有填充?

我认为我缺少一些小但非常重要的配置。

我的环境

  1. 使用 Maven Sql 插件和 Maven Liquibase 插件设置 HSQLDB。
  2. Spring/Hibernate Web 应用

填充数据库和运行应用程序的步骤

  1. 运行 Sql Maven 插件在 HSQL 数据库中创建 3 个架构

  2. 运行 Maven liquibase 插件,填充 ddl 和查找数据

我在 Maven 中用于设置 hsql 的 jdbc url 是:jdbc:hsqldb:file:${project.basedir}/target/db/build;shutdown=true
它转换为:jdbc:hsqldb:file:/Users/myHomeDir/work/myProj/target/db/build;shutdown=true

我已确认 hsql 数据库文件已创建并填充 - build.script 文件中的插入语句按预期存在。我可以使用 RazorSQL 连接到数据库并查看现有的数据和表。

运行应用

我在 Spring 配置中配置了数据源,如下所示:

<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
        <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
        <property name="url" value="jdbc:hsqldb:file:/Users/myHomeDir/work/myProj/target/db/build;shutdown=true" />
        <property name="username" value="sa" />
        <property name="password" value="" />

我已经启动了应用程序并看到 Hibernate/Spring 建立了与数据库的连接。创建了一个database.lck 文件,因此我知道应用程序已建立连接。 (此外,我已确保 RazorSQL 已关闭且不同时使用数据库)。

错误

错误表明数据库实体不存在:

[INFO] Started Jetty Server
Hibernate: 
    select
        this_.id as id5_2_,
        this_.created_date as created2_5_2_,
        this_.creating_user_id as creating3_5_2_,
        this_.email as email5_2_,
        this_.first_name as first5_5_2_,
        this_.is_enabled as is6_5_2_,
        this_.last_login_date as last7_5_2_,
        this_.last_modified_date as last8_5_2_,
        this_.last_modifying_user_id as last9_5_2_,
        this_.last_name as last10_5_2_,
        this_.login as login5_2_,
        this_.middle_initial as middle12_5_2_,
        this_.password_hash as password13_5_2_,
        this_.password_history as password14_5_2_,
        this_.suffix as suffix5_2_,
        roles2_.user_id as user1_5_4_,
        role3_.id as role2_4_,
        role3_.id as id3_0_,
        role3_.code as code3_0_,
        role3_.description as descript3_3_0_,
        role3_.name as name3_0_,
        role3_.type_id as type5_3_0_,
        roletype4_.id as id4_1_,
        roletype4_.description as descript2_4_1_ 
    from
        security.user this_ 
    left outer join
        security.user_role roles2_ 
            on this_.id=roles2_.user_id 
    left outer join
        security.role role3_ 
            on roles2_.role_id=role3_.id 
    left outer join
        security.role_type roletype4_ 
            on role3_.type_id=roletype4_.id 
    where
        this_.login=?
[01/20/2012 17:30:18,440] WARN : org.hibernate.util.JDBCExceptionReporter - SQL Error: -5501, SQLState: 42501
[01/20/2012 17:30:18,440] ERROR: org.hibernate.util.JDBCExceptionReporter - user lacks privilege or object not found: USER
2012-01-20 17:30:18.443:WARN::/my-webapp/j_spring_security_check
org.hibernate.exception.SQLGrammarException: could not execute query

最佳答案

请问一下,不会是表名(USER)与SQL关键字冲突造成的吗?

尝试使用不同的表名称,或者至少配置 Hibernate 来转义它 (@Table(name = "\"user\""))。

关于spring - HQSLDB——即使文件有内容,基于文件的数据库还是空的?为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8973470/

相关文章:

java - DDD 示例应用程序 - hsqldb 在哪里?

java - 在 Windows 服务中运行 Spring Integration;不为 "Trigger"入站

java - spring-data-aerospike `findAll(ids)` 结果返回 NULL

java - HSQLDB: count(*) 返回小数

java - 插入的条目不会永久保留在数据库中

mysql - 让hibernate指向与DBUnit相同的DB连接

java - 如何从 application.yml 文件注入(inject)属性?

java - Spring嵌入式数据库IllegalState错误

java - Spring Batch 3.0.2 与 Spring Core 4.1.x 的集成 - 使用 @EnableBatchProcessing 的合适方法是什么?

performance - Persistence.createEntityManager()与Hibernate一起非常缓慢