我希望Hibernate为id列自动生成以下SQL:
create table test (id bigint not null auto_increment)
以下两个映射都将触发该SQL。到底有什么区别?我为什么要用其中一个而不是另一个呢?
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
@GenericGenerator(name = "native", strategy = "native")
private Long id;
我使用MySQL,Spring-boot-2和Hibernate-5。
我只想问IDENTITY
和AUTO with native
的不同,因为两者都会导致sql
创造声明。
发布于 2018-08-03 10:50:24
参考:
https://www.thoughts-on-java.org/jpa-generate-primary-keys/
https://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing
会解决你的问题。
https://stackoverflow.com/questions/-100005899
复制相似问题