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 2019/12/11 03:43:04 UTC

[GitHub] [incubator-shardingsphere] peiyou opened a new issue #3713: How do you return the auto-generated id after inserting data?

peiyou opened a new issue #3713: How do you return the auto-generated id after inserting data?
URL: https://github.com/apache/incubator-shardingsphere/issues/3713
 
 
   How do you return the auto-generated id after inserting data?
   
   My configuration:
   spring.shardingsphere.sharding.tables.transaction.key-generator.column=id
   spring.shardingsphere.sharding.tables.transaction.key-generator.type=SNOWFLAKE
   spring.shardingsphere.sharding.tables.transaction.key-generator.props.worker.id=123
   
   spring.shardingsphere.sharding.tables.transaction_item.key-generator.column=id
   spring.shardingsphere.sharding.tables.transaction_item.key-generator.type=SNOWFLAKE
   spring.shardingsphere.sharding.tables.transaction_item.key-generator.props.worker.id=124
   
   LOG:
   INSERT INTO transaction_201912  ( user_id,amount,created_time , id) VALUES(?, ?, ?, ?) ::: [1, 300, 2019-12-11 11:23:27.853, 411482226929676289]
   
   I want to get the auto-generated id after inserting the data.
   
   My code:
   Transaction transaction = new Transaction();
           transaction.setUserId(userId);
           transaction.setAmount(amount);
           transaction.setCreatedTime(new Date());
           transactionService.insert(transaction);
   
           TransactionItem transactionItem = new TransactionItem();
           transactionItem.setTransactionId(transaction.getId());
           transactionItem.setNum(num);
           transactionItem.setGoodName("1");
           transactionItem.setPrice(price);
           transactionItem.setCreatedTime(new Date());
   
           transactionItemService.insert(transactionItem);
   BUT:
   transaction.getId() is null.   
   What should I do?

----------------------------------------------------------------
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


With regards,
Apache Git Services