apache/shardingsphere-example

Sharding value must implements Comparable.

Opened this issue · 0 comments

Bug Report

Which version of ShardingSphere did you use?

org.apache.shardingsphere sharding-jdbc-spring-boot-starter 4.1.0
    <!-- for spring namespace -->
    <dependency>
        <groupId>org.apache.shardingsphere</groupId>
        <artifactId>sharding-jdbc-spring-namespace</artifactId>
        <version>4.1.0</version>
    </dependency>

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-JDBC

Expected behavior

SNOWFLAKE config can use

Actual behavior

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

Reason analyze (If you can)

when insert can not bind genrate sharding value

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Example codes for reproduce this issue (such as a github link).

sharding:
tables:
t_order:
key-generator:
column: order_no
type: SNOWFLAKE
actual-data-nodes: ds-$->{2019..2020}.t_order$->{0..1}
database-strategy:
standard:
sharding-column: create_date
precise-algorithm-class-name: com.bule.spring.dao.sharding.TimeDatabaseShardingAlgorithm
table-strategy:
inline:
sharding-column: order_no
algorithm-expression: t_order$->{order_no % 2}

<resultMap id="BaseResultMap" type="com.bule.spring.domain.Order">
    <id column="order_no" property="orderNo"/>
    <result column="order_id"  property="orderId"/>
    <result column="user_id" property="userId"/>
    <result column="status" property="status"/>
    <result column="create_date" property="createDate"/>
</resultMap>


<insert id="insert" parameterType="com.bule.spring.domain.Order" >
    INSERT INTO t_order (
       order_id,order_no, user_id, status,create_date
    )
    VALUES (
        #{orderId,jdbcType=INTEGER},
        #{orderNo,jdbcType=BIGINT},
        #{userId,jdbcType=INTEGER},
        #{status,jdbcType=INTEGER},
        #{createDate,jdbcType=TIMESTAMP}
    )
</insert>

@test
public void testInsert() {
for (int i = 0; i < 10; i++) {
Order order = new Order();
order.setOrderId(Long.valueOf(i));
order.setUserId(20001);
order.setStatus("insert");
order.setCreateDate(DateUtils.addYears(new Date(),-1));
// order.setOrderNo(IdWorker.getId());
orderShardingMapper.insert(order);
}
for (int i = 0; i < 10; i++) {
Order order = new Order();
order.setOrderId(Long.valueOf(i));
order.setUserId(20001);
order.setStatus("insert");
order.setCreateDate(new Date());
//order.setOrderNo(IdWorker.getId());
orderShardingMapper.insert(order);
}
}