gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 06:00:26 25 4
gpt4 key购买 nike

各位,

我的问题

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

我想我错过了一些小的,但是 非常重要 配置。

我的环境

  • 使用 Maven Sql 插件和 Maven Liquibase 插件设置 HSQLDB。
  • Spring/Hibernate Webapp

  • 填充数据库和运行应用程序的步骤
  • 运行Sql Maven插件在HSQL数据库中创建3个模式
  • 运行 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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com