3.4.3.2
该问题是如何引起的?(确定最新版也有问题再提!!!)
达梦数据库表中无自增列,只有两列组成了复合主键,但是db-config配置了id-type: auto,插入一行提示违反唯一性约束
重现步骤(如果有就写完整)
CREATE TABLE "UMS"."UMS_USER_TENANT"
"USER_ID" INT NOT NULL,
"TENANT_ID" INT NOT NULL,
NOT CLUSTER PRIMARY KEY("USER_ID", "TENANT_ID")) STORAGE(ON "MAIN", CLUSTERBTR) ;
COMMENT ON TABLE "UMS"."UMS_USER_TENANT" IS '用户和租户关联表';
COMMENT ON COLUMN "UMS"."UMS_USER_TENANT"."TENANT_ID" IS '租户ID';
COMMENT ON COLUMN "UMS"."UMS_USER_TENANT"."USER_ID" IS 'userId';
CREATE UNIQUE INDEX "PRIMARY" ON "UMS"."UMS_USER_TENANT"("USER_ID" ASC,"TENANT_ID" ASC) STORAGE(ON "MAIN", CLUSTERBTR) ;
java bean:
package com.koalii.ums.dao.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.koalii.kaas.common.core.domain.BaseEntity;
import com.koalii.kaas.gas.core.domain.BaseInfoEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Author
Administrator
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
@TableName("ums_user_tenant")
public class UmsUserTenant extends Model {
private Long userId;
private Long tenantId;
@TableField(exist = false)
private Date createTime;
@TableField(exist = false)
private Date updateTime;
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17aae464] from current transaction
==> Preparing: INSERT INTO ums_user_tenant ( USER_ID, TENANT_ID ) VALUES ( ?, ? )
==> Parameters: 108(Long), 9(Long)
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17aae464]
11:22:15.357 [qtp1203331554-62] DEBUG o.s.j.s.SQLErrorCodeSQLExceptionTranslator - [doTranslate,289] - Unable to translate SQLException with Error code '-6602', will now try the fallback translator
11:22:15.358 [qtp1203331554-62] DEBUG o.s.j.s.SQLStateSQLExceptionTranslator - [doTranslate,98] - Extracted SQL state class '23' from value '23000'
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17aae464]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17aae464]
11:22:15.358 [qtp1203331554-62] DEBUG o.s.j.s.JdbcTransactionManager - [processRollback,833] - Initiating transaction rollback
11:22:15.358 [qtp1203331554-62] DEBUG o.s.j.s.JdbcTransactionManager - [doRollback,345] - Rolling back JDBC transaction on Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@6dfba32b]
11:22:15.359 [qtp1203331554-62] DEBUG o.s.j.s.JdbcTransactionManager - [doCleanupAfterCompletion,389] - Releasing JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@6dfba32b] after transaction
11:22:15.363 [qtp1203331554-62] ERROR c.k.u.c.DefaultExceptionController - [error,125] - execute error. [org.springframework.dao.DataIntegrityViolationException] - [{}]
org.springframework.dao.DataIntegrityViolationException:
Error updating database. Cause: dm.jdbc.driver.DMException: 违反表[UMS_USER_TENANT]唯一性约束
The error may exist in com/koalii/ums/dao/mapper/UmsUserTenantMapper.java (best guess)
The error may involve com.koalii.ums.dao.mapper.UmsUserTenantMapper.insert-Inline
The error occurred while setting parameters
SQL: INSERT INTO ums_user_tenant ( USER_ID, TENANT_ID ) VALUES ( ?, ? )
Cause: dm.jdbc.driver.DMException: 违反表[UMS_USER_TENANT]唯一性约束
; 违反表[UMS_USER_TENANT]唯一性约束; nested exception is dm.jdbc.driver.DMException: 违反表[UMS_USER_TENANT]唯一性约束
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:104)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:91)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
at com.sun.proxy.$Proxy103.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:272)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:59)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
at com.sun.proxy.$Proxy135.insert(Unknown Source)
at com.koalii.ums.dao.service.impl.UmsTenantServiceImpl.saveUserTenant(UmsTenantServiceImpl.java:435)
### 该问题是如何引起的?(确定最新版也有问题再提!!!)
达梦数据库表中无自增列,只有两列组成了复合主键,但是db-config配置了id-type: auto,插入一行提示违反唯一性约束
### 重现步骤(如果有就写完整)
![mybatis-plus配置:主键id全局自增](https://images.gitee.com/uploads/images/2021/1223/113751_65b71e7b_1518745.png "mybatis-plus配置.png")
CREATE TABLE "UMS"."UMS_USER_TENANT"
"USER_ID" INT NOT NULL,
"TENANT_ID" INT NOT NULL,
NOT CLUSTER PRIMARY KEY("USER_ID", "TENANT_ID")) STORAGE(ON "MAIN", CLUSTERBTR) ;
COMMENT ON TABLE "UMS"."UMS_USER_TENANT" IS '用户和租户关联表';
COMMENT ON COLUMN "UMS"."UMS_USER_TENANT"."TENANT_ID" IS '租户ID';
COMMENT ON COLUMN "UMS"."UMS_USER_TENANT"."USER_ID" IS 'userId';
CREATE UNIQUE INDEX "PRIMARY" ON "UMS"."UMS_USER_TENANT"("USER_ID" ASC,"TENANT_ID" ASC) STORAGE(ON "MAIN", CLUSTERBTR) ;
java bean:
package com.koalii.ums.dao.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.koalii.kaas.common.core.domain.BaseEntity;
import com.koalii.kaas.gas.core.domain.BaseInfoEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
* @author Administrator
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
@TableName("ums_user_tenant")
public class UmsUserTenant extends Model<UmsUserTenant> {
* 用户id
private Long userId;
* 租户id
private Long tenantId;
@TableField(exist = false)
private Date createTime;
@TableField(exist = false)
private Date updateTime;
### 报错信息
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17aae464] from current transaction
==> Preparing: INSERT INTO ums_user_tenant ( USER_ID, TENANT_ID ) VALUES ( ?, ? )
==> Parameters: 108(Long), 9(Long)
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17aae464]
11:22:15.357 [qtp1203331554-62] DEBUG o.s.j.s.SQLErrorCodeSQLExceptionTranslator - [doTranslate,289] - Unable to translate SQLException with Error code '-6602', will now try the fallback translator
11:22:15.358 [qtp1203331554-62] DEBUG o.s.j.s.SQLStateSQLExceptionTranslator - [doTranslate,98] - Extracted SQL state class '23' from value '23000'
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17aae464]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17aae464]
11:22:15.358 [qtp1203331554-62] DEBUG o.s.j.s.JdbcTransactionManager - [processRollback,833] - Initiating transaction rollback
11:22:15.358 [qtp1203331554-62] DEBUG o.s.j.s.JdbcTransactionManager - [doRollback,345] - Rolling back JDBC transaction on Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@6dfba32b]
11:22:15.359 [qtp1203331554-62] DEBUG o.s.j.s.JdbcTransactionManager - [doCleanupAfterCompletion,389] - Releasing JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@6dfba32b] after transaction
11:22:15.363 [qtp1203331554-62] ERROR c.k.u.c.DefaultExceptionController - [error,125] - execute error. [org.springframework.dao.DataIntegrityViolationException] - [{}]
org.springframework.dao.DataIntegrityViolationException:
### Error updating database. Cause: dm.jdbc.driver.DMException: 违反表[UMS_USER_TENANT]唯一性约束
### The error may exist in com/koalii/ums/dao/mapper/UmsUserTenantMapper.java (best guess)
### The error may involve com.koalii.ums.dao.mapper.UmsUserTenantMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO ums_user_tenant ( USER_ID, TENANT_ID ) VALUES ( ?, ? )
### Cause: dm.jdbc.driver.DMException: 违反表[UMS_USER_TENANT]唯一性约束
; 违反表[UMS_USER_TENANT]唯一性约束; nested exception is dm.jdbc.driver.DMException: 违反表[UMS_USER_TENANT]唯一性约束
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:104)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:91)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
at com.sun.proxy.$Proxy103.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:272)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:59)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
at com.sun.proxy.$Proxy135.insert(Unknown Source)
at com.koalii.ums.dao.service.impl.UmsTenantServiceImpl.saveUserTenant(UmsTenantServiceImpl.java:435)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
https://gitee.com/baomidou/mybatis-plus.git
baomidou
mybatis-plus
mybatis-plus