AutoIncrement列带ID插入数据时没有Commit

业务场景中,需要预留(1 ~ 100)的ID给系统规则使用。所以会先使用插入将AutoIncrement列的id偏移到一个特定的值(如:100),然后“带ID调用Insert插入系统规则”。 当带ID插入时,由于没有commit,会被rollback掉。
This commit is contained in:
brookechen 2023-05-16 19:17:42 +08:00
parent 23be940bad
commit 95356ac403
1 changed files with 14 additions and 14 deletions

View File

@ -353,6 +353,7 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
}
if needCommit { if needCommit {
if err := session.Commit(); err != nil { if err := session.Commit(); err != nil {
return 0, err return 0, err
@ -361,7 +362,6 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) {
if id == 0 { if id == 0 {
return 0, errors.New("insert successfully but not returned id") return 0, errors.New("insert successfully but not returned id")
} }
}
defer handleAfterInsertProcessorFunc(bean) defer handleAfterInsertProcessorFunc(bean)