最近公司要将系统进行国产化数据库人大金仓的适配,在适配过程中发现了许多问题,在此记录
1、引入依赖
根据安装的数据库版本决定需要引入对应的驱动版本和数据库方言,我们安装的是kingbaseESV8版本,所以我们引入8.2.0的驱动,我们是将jar包推到私服上的,所以直接通过依赖引入
<dependency>
<groupId>com.esen.jdbc</groupId>
<artifactId>kingbasejdbc4</artifactId>
<version>8.2.0</version>
</dependency>
<dependency>
<groupId>org.hibernate.dialect</groupId>
<artifactId>KingbaseDialect</artifactId>
<version>1.0</version>
</dependency>
https://pan.baidu.com/s/1PLsbXPoDXzji8ToEgD_eNA
提取码:qwer
2、配置数据库连接信息和数据库方言
#KINGBASE
orm.database=
orm.databasePlatform=org.hibernate.dialect.KingbaseDialect
# 人大金仓
spring.datasource.driverClassName=com.kingbase8.Driver
spring.datasource.url=jdbc:kingbase8://localhost:54321/TEST
spring.datasource.username=SYSTEM
spring.datasource.password=123456
3、自动建表问题
引用的Hibernate5.6.9版本,自动建表时会进行元数据的提取
默认为null,而KingbaseDialect中有具体返回,所以会执行后续的元数据提取操作
提取元数是从设置的QuerySequencesString中设置的sql执行查询后从结果中提取sequence_name,sequence_catalog,sequence_schema等信息,如果为空,则会抛出异常:The column name sequence_catalog was not found in this ResultSet
public Iterable<SequenceInformation> extractMetadata(ExtractionContext extractionContext) throws SQLException {
String lookupSql = extractionContext.getJdbcEnvironment().getDialect().getQuerySequencesString();
return lookupSql == null ? SequenceInformationExtractorNoOpImpl.INSTANCE.extractMetadata(extractionContext) : (Iterable)extractionContext.getQueryResults(lookupSql, (Object[])null, (resultSet) -> {
IdentifierHelper identifierHelper = extractionContext.getJdbcEnvironment().getIdentifierHelper();
ArrayList sequenceInformationList = new ArrayList();
while(resultSet.next()) {
sequenceInformationList.add(new SequenceInformationImpl(new QualifiedSequenceName(identifierHelper.toIdentifier(this.resultSetCatalogName(resultSet)), identifierHelper.toIdentifier(this.resultSetSchemaName(resultSet)), identifierHelper.toIdentifier(this.resultSetSequenceName(resultSet))), this.resultSetStartValueSize(resultSet), this.resultSetMinValue(resultSet), this.resultSetMaxValue(resultSet), this.resultSetIncrementValue(resultSet)));
}
return sequenceInformationList;
});
}
protected String sequenceNameColumn() {
return "sequence_name";
}
protected String sequenceCatalogColumn() {
return "sequence_catalog";
}
protected String sequenceSchemaColumn() {
return "sequence_schema";
}
protected String sequenceStartValueColumn() {
return "start_value";
}
protected String sequenceMinValueColumn() {
return "minimum_value";
}
protected String sequenceMaxValueColumn() {
return "maximum_value";
}
protected String sequenceIncrementColumn() {
return "increment";
}
解决方案
1、降低Hibernate版本,5.1.0版本执行提取元数据操作时,是加入空的Identifier对象,所以不会报此错误。
2、重写方言的getQuerySequencesString方法,直接返回null,因为通过对比发现mysql的方言并没有重写此方法,所以认为此处返回null,然后不进行元数据提取不会产生影响,经测试能成功建表
public class KunKingbaseDialect extends KingbaseDialect {
public KunKingbaseDialect() {
super();
}
@Override
public String getQuerySequencesString() {
return null;
}
}