You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/04/01 08:24:37 UTC
[GitHub] [shardingsphere] HughWick opened a new issue #9903: Why can't the primary key be a string?
HughWick opened a new issue #9903:
URL: https://github.com/apache/shardingsphere/issues/9903
When I use mybatis plus for data insertion, I get the following error:
```
### The error occurred while setting parameters
### SQL: INSERT INTO PING_LOGS ( SERIAL_NO, IP, TIME, STATUS, CREATE_DATE, DELETE_FLAG ) VALUES ( ?, ?, ?, ?, ?, ? )
### Cause: groovy.lang.MissingMethodException: No signature of method: java.lang.String.mod() is applicable for argument types: (java.lang.Integer) values: [3]
Possible solutions: drop(int), any(), find(), use([Ljava.lang.Object;), is(java.lang.Object), find(java.lang.CharSequence)
```
My entity class:
```
@Data
@TableName("PING_LOGS")
public class PingLogs2 {
private long id;//
@TableField("SERIAL_NO")
private String serialNo;//
@TableField("IP")
private String ip;//
@TableField("TIME")
private double time;
@TableField("STATUS")
private int status;
@TableField("REMARK")
private String remark;
}
```
My yml configuration.
```
shardingsphere:
datasource:
names: ds0,ds1
ds0:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.1.81:3306/device?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=PRC
username: root
password: TH##123456$
ds1:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.1.81:3306/monitor_sharding?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=PRC
username: root
password: TH##123456$
sharding:
defaultDataSourceName: ds0
tables:
PING_LOGS:
actualDataNodes: ds1.PING_LOGS_${0..2}
keyGenerator:
type: UUID
column: id
tableStrategy:
inline:
shardingColumn: SERIAL_NO
algorithmExpression: PING_LOGS_${SERIAL_NO % 3}
props:
sql.show: true
```
In between I also tried to use a custom primary key for the problem, but I still get the appeal error message
```
@Data
@Component
public class SimpleShardingKeyGenerator implements ShardingKeyGenerator{
private Properties properties = new Properties();
@Override
public Comparable<String> generateKey() {
return IdSequence.snowflake();
}
@Override
public String getType() {
return "UUID";
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] HughWick closed issue #9903: Why can't the primary key be a string?
Posted by GitBox <gi...@apache.org>.
HughWick closed issue #9903:
URL: https://github.com/apache/shardingsphere/issues/9903
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] HughWick commented on issue #9903: Why can't the primary key be a string?
Posted by GitBox <gi...@apache.org>.
HughWick commented on issue #9903:
URL: https://github.com/apache/shardingsphere/issues/9903#issuecomment-812319798
@dongzl I seem to have found the problem, I changed the algorithmExpression rule to "${Math.abs(SERIAL_NO.hashCode())%4}" first hashCode and then modulo and I don't have the previous data type error problem.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] HughWick commented on issue #9903: Why can't the primary key be a string?
Posted by GitBox <gi...@apache.org>.
HughWick commented on issue #9903:
URL: https://github.com/apache/shardingsphere/issues/9903#issuecomment-811880017
@dongzl I am using sharding-jdbc-spring-boot-starter:4.1.1 , spring boot :2.2.7 , I have a code written wrong when asking questions. The keyGenerator:column in my yml configuration is actually SERIAL_NO, but I forgot to change it when I uploaded it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] dongzl commented on issue #9903: Why can't the primary key be a string?
Posted by GitBox <gi...@apache.org>.
dongzl commented on issue #9903:
URL: https://github.com/apache/shardingsphere/issues/9903#issuecomment-811870071
@HughWick Hi, which version do you use? jdbc or proxy?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] HughWick commented on issue #9903: Why can't the primary key be a string?
Posted by GitBox <gi...@apache.org>.
HughWick commented on issue #9903:
URL: https://github.com/apache/shardingsphere/issues/9903#issuecomment-812291100
@dongzl Sorry, I can't create a separate project on github because it's an internal project. I suspect that the custom primary key is not working, could it be that I made a mistake when configuring the custom primary key? I followed the online tutorial for configuring custom primary keys, but I didn't find the corresponding configuration document on the website.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] dongzl commented on issue #9903: Why can't the primary key be a string?
Posted by GitBox <gi...@apache.org>.
dongzl commented on issue #9903:
URL: https://github.com/apache/shardingsphere/issues/9903#issuecomment-812411575
Hi @HughWick , I understand `SERIAL_NO ` is `String`, if `SERIAL_NO % 3` maybe cause a mistake, you must covert the `SERIAL_NO` to number firstly. Maybe `Integer.valueOf(SERIAL_NO) % 4`, but I am not sure, you can try it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] dongzl commented on issue #9903: Why can't the primary key be a string?
Posted by GitBox <gi...@apache.org>.
dongzl commented on issue #9903:
URL: https://github.com/apache/shardingsphere/issues/9903#issuecomment-812278027
Hi @HughWick , I'm sorry, can you provide the error message and create a demo project on the github to reproduce this problem?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org