简体   繁体   English

如何使用 mySQL Workbench 从 lombok 手动设置自动生成的 ID?

[英]how to manually set auto-generated id from lombok with mySQL workbench?

I have an app with a few entities annotated with lombok's @Data , and using我有一个应用程序,其中包含一些用 lombok 的@Data注释的实体,并使用

@Id
@GeneratedValue(strategy= GenerationType.AUTO)

for the id.对于 ID。 It's generally working fine.它通常工作正常。 But I needed to manually insert a row via mySQL Workbench, with id=635.但是我需要通过 mySQL Workbench 手动插入一行,id=635。 This screwed up the app, when it tried to insert it's next row, because what it thought or calculated would be the next id, 635, already existed.这搞砸了应用程序,当它试图插入它的下一行时,因为它认为或计算出的下一个 id 635 已经存在。 I thought I could manually increment the id, but I couldn't find it anywhere via mySQL workbench.我以为我可以手动增加 id,但我无法通过 mySQL 工作台在任何地方找到它。

So where does lombok/hibernate/jpa calculate or generate the next id?那么 lombok/hibernate/jpa 在哪里计算或生成下一个 id? And is there a way to manually change it in the db, or at least with another SQL?有没有办法在数据库中手动更改它,或者至少使用另一个 SQL?

I'm not sure which framework does this, since it's using javax.persistence for the annotations, but also lombok.Data , and then in the app.properties, there is no dialect set, but I have a spring.jpa.hibernate.ddl key, so I'm not sure if that pulls in bits of hibernate as well.我不确定哪个框架lombok.Data ,因为它使用javax.persistence进行注释,但也使用lombok.Data ,然后在 app.properties 中,没有设置方言,但我有一个spring.jpa.hibernate.ddl键,所以我不确定这是否也会引起一些休眠。

I guess I needed to do more googling before posting.我想我需要在发布之前做更多的谷歌搜索。 Found this answer here : 在这里找到了这个答案:

ALTER TABLE table_name AUTO_INCREMENT = 636;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM