环境:Spring(3.2.3.RELEASE) + MyBatis(3.2.2) + HSQL(2.3.0)
<resultMap id="hashMapResult" type="java.util.HashMap">
<result property="key" column="key" />
<result property="value" column="value" />
</resultMap>
<select id="getSettings" resultMap="hashMapResult">
SELECT "KEY","VALUE" from "PUBLIC"."SETTINGS";
</select>
create table "SETTINGS" (
"KEY" varchar(255) not null,
"VALUE" varchar(512) not null,
CONSTRAINT SETTINGS_KEY_UNIQUE UNIQUE("KEY")
);
网址:jdbc:hsqldb:mem:mydb;sql.syntax_mys=true;shutdown=true;
使用内存数据库时,出现如下错误:
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: SETTINGS
at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.3.0.jar:2.3.0]
at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.3.0.jar:2.3.0]
at org.hsqldb.SchemaManager.getTable(Unknown Source) ~[hsqldb-2.3.0.jar:2.3.0]
at org.hsqldb.ParserDQL.readTableName(Unknown Source) ~[hsqldb-2.3.0.jar:2.3.0]
at org.hsqldb.ParserDQL.readTableOrSubquery(Unknown Source) ~[hsqldb-2.3.0.jar:2.3.0]
at org.hsqldb.ParserDQL.XreadTableReference(Unknown Source) ~[hsqldb-2.3.0.jar:2.3.0]
但是当使用基于文件的数据库时 jdbc:hsqldb:file:mydb;sql.syntax_mys=true;shutdown=true; 完全没有错误。
我正在使用 Spring 的 EmbeddedDatabaseFactory 来初始化数据库:
try {
EmbeddedDatabaseFactory dbFactory = new EmbeddedDatabaseFactory();
DatabaseConfig dbConfig = appConfig.getDbConfig();
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
populator.setContinueOnError(false);
populator.setIgnoreFailedDrops(false);
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
populator.addScript(resourceLoader.getResource(dbConfig
.getSqlSchemeFile()));
populator.addScript(resourceLoader.getResource(dbConfig
.getSqlDataFile()));
dbFactory.setDatabasePopulator(populator);
dbFactory.setDatabaseName(dbConfig.getName());
dbFactory.setDatabaseConfigurer(new HSQLConfigurer(dbConfig));
return dbFactory.getDatabase();
} catch (Exception e) {
logger.error("dataSource error", e); //$NON-NLS-1$
return null;
}
有谁知道为什么?