[Solved] ShardingSphere Error: Sharding value must implements Comparable.

Shardingsphere integrates mybatis plus and reports an error. Java.lang.illegalargumentexception: sharding value must implements comparable.

error reason
because shardingsphere’s ID generation strategy is configured in the configuration file, ID is used as the partition key here, and shardingsphere will automatically generate ID value when saving data.

spring.shardingsphere.sharding.tables.user.key-generator.column = id
spring.shardingsphere.sharding.tables.user.key-generator.type = SNOWFLAKE

However, the annotation @tableid is pasted on the entity class, which conflicts with mybatis plus.


@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "`user`")
public class User implements Serializable {
    @TableId(value = "id", type = IdType.INPUT)
    private Long id;

    @TableField(value = "`name`")
    private String name;

    @TableField(value = "address")
    private String address;

    @TableField(value = "birthday")
    private Date birthday;
}

The solution is not to paste @tableid when the primary key is used as the partition key. If you write SQL through an XML file, the primary key column does not need to be written

Read More: