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/06/03 04:43:27 UTC

[GitHub] [incubator-shardingsphere] wowojyc opened a new issue #2489: Where could I find the example for key generator code?

wowojyc opened a new issue #2489: Where could I find the example for key generator code?
URL: https://github.com/apache/incubator-shardingsphere/issues/2489
 
 
   I use raw java code,
   
   `
   KeyGeneratorConfiguration keyGeneratorConfiguration = new KeyGeneratorConfiguration("SNOWFLAKE", "goods_id", new Properties());
           tableRuleConfiguration.setKeyGeneratorConfig(keyGeneratorConfiguration);
   `
   and I use jpa to insert data in the for loop;
   `
           for (int i = 1; i <= 40; i++) {
               Goods goods = new Goods();
               goods.setGoodsName("shangpin" + i);
               goods.setGoodsType((long) (i + 1));
               long goodsId = goodsRepository.save(goods).getGoodsId();
               System.out.println("goods id:" + goodsId);
           }
   `
   
   and My database is db_01 and db_02, the table name is goods_0 and goods_1.
   The entity code is 
   `
   @Entity
   @Table(name = "goods")
   public class Goods {
   
       @Id
       @GeneratedValue(strategy = GenerationType.IDENTITY)
       @Column(name = "goods_id")
       private Long goodsId;
   
       private String goodsName;
   `
   But when i call the insert method, I catch the exception 
   **A different object with the same identifier value was already associated with the session**
   
   Do I miss some important configuration?

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