Spring HQSLDB--基于文件的数据库为空,即使文件有内容?为什么?
各位 我的问题 为什么我用模式预先填充的基于HSQLDB文件的数据库在以后连接时没有填充数据 我想我缺少了一些小的,但非常重要的配置 我的环境Spring HQSLDB--基于文件的数据库为空,即使文件有内容?为什么?,spring,hsqldb,Spring,Hsqldb,各位 我的问题 为什么我用模式预先填充的基于HSQLDB文件的数据库在以后连接时没有填充数据 我想我缺少了一些小的,但非常重要的配置 我的环境 带有Maven Sql插件和Maven Liquibase插件的HSQLDB设置 Spring/HibernateWebApp 填充数据库和运行应用程序的步骤 运行SQLMaven插件在HSQL数据库中创建3个模式 运行Maven liquibase插件,填充ddl和查找数据 我在Maven中用于设置hsql的jdbc url是:jdbc:hsqldb:
jdbc:hsqldb:file:${project.basedir}/target/db/build;shutdown=true
它翻译成:
jdbc:hsqldb:file:/Users/myHomeDir/work/myProj/target/db/build;关机=真
我已经确认hsql数据库文件已创建并填充——build.script文件中的insert语句如预期的那样存在。我可以使用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="" />
请确认一下,它不是由表名(
USER
)与SQL关键字冲突引起的吗
请尝试使用不同的表名,或者至少将Hibernate配置为转义(
@table(name=“\”user\”)
)。感谢您找到了大海捞针。结果是我有“用户”和“角色”表导致了这个问题。我了解了如何使用hibernate引用标识符:“您可以强制Hibernate在生成的SQL中引用标识符,方法是将表名或列名括在映射文档的反勾中。Hibernate将为SQL方言使用正确的引号样式。这通常是双引号,但SQL Server使用括号,MySQL使用回号。“我希望有一种方法告诉它全局转义标识符。
[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