【发布时间】:2012-02-16 21:51:45
【问题描述】:
伙计们,
我的问题
为什么我已经预填充了一个基于 HSQLDB 文件的数据库,而我稍后连接到它时却没有填充数据?
我想我缺少一些小但非常重要的配置。
我的环境
- 使用 Maven Sql 插件和 Maven Liquibase 插件设置 HSQLDB。
- Spring/Hibernate Web 应用程序
填充数据库和运行应用程序的步骤
运行 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 配置中配置了 DataSource,如下所示:
<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
【问题讨论】: