xrayw opened a new issue, #24328:
URL: https://github.com/apache/shardingsphere/issues/24328
## Question
I have some table, such as
- user
- user_0
- user_1
I want always insert data to user and i'll move old data to user_0/user_1
manually at sometime.
but when i run my code, i got the error:
> org.mybatis.spring.MyBatisSystemException: nested exception is
org.apache.ibatis.executor.ExecutorException: Error getting generated key or
setting result to parameter object. Cause:
org.apache.ibatis.executor.result.ResultMapException: Error attempting to get
column #1 from result set. Cause: java.lang.NullPointerException: **ResultSet
should call next or has no more data**.
my config:
```sql
CREATE TABLE `user` (
`id` bigint NOT NULL AUTO_INCREMENT,
`uu` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
```
sharding.yml
```yml
mode:
type: Standalone
repository:
type: JDBC
dataSources:
ds_0:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
url:
jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8
password: xxx
username: xxx
driver-class-name: com.mysql.jdbc.Driver
rules:
- !SHARDING
defaultKeyGenerateStrategy:
column: id
keyGeneratorName: autoinc
defaultDatabaseStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: db_master
tables:
user:
actualDataNodes: ds_0.user
tableStrategy:
standard:
shardingColumn: id
shardingAlgorithmName: user_archive
keyGenerateStrategy:
column: id
keyGeneratorName: autoinc
keyGenerators:
autoinc:
type: AUTOINC
shardingAlgorithms:
db_master:
type: INLINE
props:
algorithm-expression: ds_0
user_archive:
type: CLASS_BASED
props:
strategy: STANDARD
algorithmClassName: xxxx.UserShardingAlgorithm
props:
sql-show: true
```
UserShardingAlgorithm
```java
public class UserShardingAlgorithm implements
StandardShardingAlgorithm<Long> {
@Override
public String getType() {
return "USER_SHARD";
}
@Override
public String doSharding(Collection<String> availables,
PreciseShardingValue<Long> shardingValue) {
return "user";
}
@Override
public Collection<String> doSharding(Collection<String> collection,
RangeShardingValue<Long> rangeShardingValue) {
return null;
}
@Override
public Properties getProps() {
return null;
}
@Override
public void init(Properties properties) {
}
}
```
AutoIncrementKeyGeneratorAlgorithm.java
```java
public class AutoIncrementKeyGeneratorAlgorithm implements
KeyGenerateAlgorithm {
@Override
public Comparable<?> generateKey() {
return null;
}
@Override
public Properties getProps() {
return null;
}
@Override
public String getType() {
return "AUTOINC";
}
@Override
public void init(Properties properties) {
}
}
```
entity
```java
@Data
public class User {
@TableId(type = IdType.AUTO)
private Long id;
private String uu;
}
```
My test code:
```java
@Autowired
private UserMapper userMapper;
@Test
public void testJDBC() {
User user = new User();
user.setUu("text_uu");
userMapper.insert(user); // error occurs here because can not get
the last_insert_id()
System.out.println(user.getId());
}
```
UserMapper
```java
@Mapper
public interface UserMapper extends BaseMapper<User> {}
```
``` log
Logic SQL: insert into user (uu) values (?)
Actual SQL: ds_0 ::: insert into user (uu, id) values (?, ?) ::: [text_uu,
null]
```
I want to know how i can get the auto increment paimary key's value.
Thanks
--
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:
[email protected]
For queries about this service, please contact Infrastructure at:
[email protected]