民间,
为什么基于HSQLDB文件的数据库预先填充了架构,并且在以后连接时未填充数据?
我想我错过了一些小的,但 HUGELY IMPORTANT 配置。
运行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文件中的insert语句按预期存在。我可以使用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
答案 0 :(得分:3)
只是为了确保,不能由表名(USER
)与SQL关键字的冲突引起吗?
尝试使用不同的表名,或者至少配置Hibernate来逃避它(@Table(name = "\"user\"")
)。