Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The primary key is sharding column created the key value by the GeneratedKey config 。 is it okay? #10274

Closed
XUZHOUWANG opened this issue May 7, 2021 · 8 comments

Comments

@XUZHOUWANG
Copy link

table:

@TableName("t_user")
@DaTa
public class User implements Serializable {

@TableId(type = IdType.INPUT)
private Long id;
private String name;
private Date gmtCreate;
private Date gmtModified;
private String phone;
private Integer isDeleted;

}

config

sharding:
tables:
t_user:
actual-data-nodes: skshardingjdbc.t_user_$->{0..1}
logicTable: t_user
tableStrategy:
inline:
shardingColumn: id
algorithmExpression: t_user_$->{id % 2}
keyGenerator:
type: UUID
column: id

error

SQL: INSERT INTO t_user ( id, name, gmt_create, gmt_modified, phone ) VALUES ( ?, ?, ?, ?, ? )

Cause: java.lang.IllegalArgumentException: Sharding value must implements Comparable.

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)
... 37 more
@avalon5666
Copy link
Contributor

  1. Use "@TableId(type = IdType.AUTO)"
  2. id's type in class not match uuid

@XUZHOUWANG
Copy link
Author

@XUZHOUWANG
Copy link
Author

  1. Use "@TableId(type = IdType.AUTO)"
  2. id's type in class not match uuid

no,I want to create the id by shardingsphere; the definition of User is okay.

@avalon5666
Copy link
Contributor

Follow step 1 ~ 2

@XUZHOUWANG
Copy link
Author

Follow step 1 ~ 2

it‘s okay. but i want to the value of the primary key created by the snowflake set by the sharding configuration. while step 1~2,the id is created by the mybatis-plus framework.

@avalon5666
Copy link
Contributor

How to confirm the id is created by the mybatis-plus framework?

@avalon5666
Copy link
Contributor

avalon5666 commented May 8, 2021

"IdType.AUTO" is created by the database,it will create by shardingsphere database middleware,mybatis-plus do nothing.

@XUZHOUWANG
Copy link
Author

"IdType.AUTO" is created by the database,it will create by shardingsphere database middleware,mybatis-plus do nothing.

it's okay. I try it. it's fine. I know the "IdType.ASSIGN_ID" procedure. But I don't really try the "IdType.AUTO". thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants