반응형
MariaDB 시퀀스가 음수를 생성하는 이유는 무엇입니까?
최근에 운행 중입니다.MariaDB 10.3.7
시퀀스를 제공하는 서버.
다음과 같이 시퀀스를 만들었습니다.
drop sequence if exists user_account_id_seq;
create sequence user_account_id_seq;
drop table if exists user_account;
create table user_account (
-- id bigint(20) unsigned not null auto_increment,
id bigint(20) unsigned not null default (next value for user_account_id_seq),
version int(10) unsigned not null,
firstname varchar(255) not null,
lastname varchar(255) not null,
password varchar(100),
password_salt varchar(50),
readable_password varchar(50),
email varchar(50) not null,
confirmed_email bit(1) not null check (confirmed_email in (0, 1)),
work_phone varchar(20),
unique key email (email),
primary key (id)
);
drop sequence if exists user_role_id_seq;
create sequence user_role_id_seq;
drop table if exists user_role;
create table user_role (
-- id bigint(20) unsigned not null auto_increment,
id bigint(20) unsigned not null default (next value for user_role_id_seq),
version int(10) unsigned not null,
user_account_id bigint(20) unsigned not null,
role varchar(50) not null,
unique key user_role_u1 (user_account_id, role),
key user_account_id (user_account_id),
constraint user_role_fk1 foreign key (user_account_id) references user_account (id),
primary key (id)
);
다음과 같습니다.
MariaDB [useraccounttest]> show create sequence user_account_id_seq;
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
| user_account_id_seq | CREATE SEQUENCE `user_account_id_seq` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB |
+---------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
나는 왜 나의 수열이 음수를 생성하는지 궁금합니다.
19:16:42.294 [main] DEBUG org.hibernate.event.internal.AbstractSaveEventListener - Generated identifier: -29, using strategy: org.hibernate.id.enhanced.SequenceStyleGenerator
저는 다이얼을 사용하고 있습니다.org.hibernate.dialect.MariaDB103Dialect
.
구성은 다음과 같습니다.
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_generator")
@Column(name = "id", updatable = false, nullable = false)
private Long id;
...
}
@Entity
@Table(name = "user_account")
@SequenceGenerator(name = "id_generator", sequenceName = "user_account_id_seq")
public class User extends AbstractEntity {
...
}
내 속성은 다음과 같습니다.
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MariaDB103Dialect
spring.datasource.driver-class-name=net.sf.log4jdbc.DriverSpy
spring.datasource.url=jdbc:log4jdbc:mysql://localhost:3306/useraccounttest?serverTimezone=UTC
spring.datasource.username=useraccount
spring.datasource.password=mypassword
spring.jpa.show-sql=true
콘솔 로그 청크:
19:16:42.294 [main] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Participating in existing transaction
19:16:42.294 [main] DEBUG org.hibernate.event.internal.AbstractSaveEventListener - Generated identifier: -29, using strategy: org.hibernate.id.enhanced.SequenceStyleGenerator
19:16:42.295 [main] DEBUG org.hibernate.event.internal.AbstractFlushingEventListener - Processing flush-time cascades
19:16:42.295 [main] DEBUG org.hibernate.event.internal.AbstractFlushingEventListener - Dirty checking collections
19:16:42.295 [main] DEBUG org.hibernate.engine.internal.Collections - Collection found: [com.thalasoft.userdata.jpa.domain.User.userRoles#-29], was: [<unreferenced>] (initialized)
19:16:42.295 [main] DEBUG org.hibernate.event.internal.AbstractFlushingEventListener - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
19:16:42.295 [main] DEBUG org.hibernate.event.internal.AbstractFlushingEventListener - Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
19:16:42.295 [main] DEBUG org.hibernate.internal.util.EntityPrinter - Listing entities:
19:16:42.296 [main] DEBUG org.hibernate.internal.util.EntityPrinter - com.thalasoft.userdata.jpa.domain.User{userRoles=[], firstname=Stephane, password=toto, readablePassword=null, confirmedEmail=false, workPhone=null, id=-29, version=0, passwordSalt=, email=component[value]{value=stephane@thalasoft.com}, lastname=Eybert}
19:16:42.296 [main] DEBUG org.hibernate.SQL - insert into user_account (version, confirmed_email, email, firstname, lastname, password, password_salt, readable_password, work_phone, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into user_account (version, confirmed_email, email, firstname, lastname, password, password_salt, readable_password, work_phone, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
19:16:42.297 [main] DEBUG jdbc.audit - 1. PreparedStatement.new PreparedStatement returned com.zaxxer.hikari.pool.ProxyConnection.prepareStatement(ProxyConnection.java:318)
19:16:42.302 [main] DEBUG jdbc.audit - 1. Connection.prepareStatement(insert into user_account (version, confirmed_email, email, firstname, lastname, password, password_salt, readable_password, work_phone, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) returned net.sf.log4jdbc.PreparedStatementSpy@44bc2449 com.zaxxer.hikari.pool.ProxyConnection.prepareStatement(ProxyConnection.java:318)
19:16:42.302 [main] DEBUG jdbc.audit - 1. PreparedStatement.setInt(1, 0) returned com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setInt(HikariProxyPreparedStatement.java:-1)
19:16:42.303 [main] DEBUG jdbc.audit - 1. PreparedStatement.setBoolean(2, false) returned com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setBoolean(HikariProxyPreparedStatement.java:-1)
19:16:42.303 [main] DEBUG jdbc.audit - 1. PreparedStatement.setString(3, "stephane@thalasoft.com") returned com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setString(HikariProxyPreparedStatement.java:-1)
19:16:42.303 [main] DEBUG jdbc.audit - 1. PreparedStatement.setString(4, "Stephane") returned com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setString(HikariProxyPreparedStatement.java:-1)
19:16:42.304 [main] DEBUG jdbc.audit - 1. PreparedStatement.setString(5, "Eybert") returned com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setString(HikariProxyPreparedStatement.java:-1)
19:16:42.304 [main] DEBUG jdbc.audit - 1. PreparedStatement.setString(6, "toto") returned com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setString(HikariProxyPreparedStatement.java:-1)
19:16:42.304 [main] DEBUG jdbc.audit - 1. PreparedStatement.setString(7, "") returned com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setString(HikariProxyPreparedStatement.java:-1)
19:16:42.304 [main] DEBUG jdbc.audit - 1. PreparedStatement.setNull(8, 12) returned com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setNull(HikariProxyPreparedStatement.java:-1)
19:16:42.305 [main] DEBUG jdbc.audit - 1. PreparedStatement.setNull(9, 12) returned com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setNull(HikariProxyPreparedStatement.java:-1)
19:16:42.305 [main] DEBUG jdbc.audit - 1. PreparedStatement.setLong(10, -29) returned com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setLong(HikariProxyPreparedStatement.java:-1)
19:16:42.305 [main] DEBUG jdbc.sqlonly - com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
1. insert into user_account (version, confirmed_email, email, firstname, lastname, password, password_salt,
readable_password, work_phone, id) values (0, 0, 'stephane@thalasoft.com', 'Stephane', 'Eybert',
'toto', '', NULL, NULL, -29)
19:16:42.307 [main] ERROR jdbc.audit - 1. PreparedStatement.executeUpdate() insert into user_account (version, confirmed_email, email, firstname, lastname, password, password_salt,
readable_password, work_phone, id) values (0, 0, 'stephane@thalasoft.com', 'Stephane', 'Eybert',
'toto', '', NULL, NULL, -29)
com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Out of range value for column 'id' at row 1
언급URL : https://stackoverflow.com/questions/51106113/why-my-mariadb-sequence-generates-a-negative-number
반응형
'programing' 카테고리의 다른 글
ImageView(이미지 보기)에서 "애니메이션 서클"을 사용하여 작업 로드 (0) | 2023.10.19 |
---|---|
avg 및 그룹을 사용한 SQL 쿼리 (0) | 2023.10.19 |
AJAX post에서 Flask에 데이터를 가져오는 방법 (0) | 2023.10.19 |
테이블을 분할하기에 좋은 크기(행 수)는 무엇입니까? (0) | 2023.10.19 |
표에서 값이 연속적으로 발생한 횟수 (0) | 2023.10.19 |