SpringBoot+JPA适配人大金仓
近期接了个需求要适配人大金仓,下面是相关适配步骤。
在金仓官网:电科金仓-成为世界卓越的数据库产品与服务提供商
找到Kingbase8的驱动jar包,和Hibernate。
jar包可以先放在项目目录下 后续可以上传到mvn仓库。
<dependency>
<groupId>com.kingbase8.jdbc</groupId>
<artifactId>kingbase8</artifactId>
<version>9.0.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/kingbase8-9.0.0.jar</systemPath>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-core -->
<dependency>
<groupId>hibernate-4.dialect</groupId>
<artifactId>hibernate-4.dialect</artifactId>
<version>4.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/hibernate-4.dialect.jar</systemPath>
</dependency>
加完配置后要修改hibernate中的声明
Oracle模式如下所示:
在hibernate.properties 中增加如下声明:
hibernate.dialect = org.hibernate.dialect.Kingbase8Dialect
在hibernate.cfg.xml 中增加如下声明:
<property name-"dialect">org.hibernate.dialect.Kingbase8Dialect</property>
在persistence.xml 中增加如下声明:
<property name="hibernate.dialect"value="org.hibernate.dialect.KingbasegDialect"/>
我用的是nacos管理服务的 所以直接在配置文件中加了
hibernate.dialect = org.hibernate.dialect.Kingbase8Dialect。
相关配置文件如下:
spring:
datasource:
driver-class-name: com.kingbase8.Driver
url: jdbc:kingbase8://localhost:22222/kingbase
username: username
password: password
jpa:
##指定目标数据库的类型
##database-platform: org.hibernate.dialect.Kingbase8Dialect
hibernate:
##指定DDL mode(none, validate, update, create, create-drop). 当使用内嵌数据库时,默认是create-drop,否则为none.
ddl-auto: update
properties:
enable: true
bootstrap-mode: default
hibernate:
dialect: org.hibernate.dialect.Kingbase8Dialect
编写相关实体类:使用JPA或者mybatisplus都会自动创建相关表。