Apparently hibernate looks for sequence tables for generating the id. Setting the following:
@GeneratedValue(strategy = GenerationType.IDENTITY)
on the id, causes it to use the underlying db’s auto increment and not try to generate the id itself, and now it works.
把主键字段上的注解写成如上即可
How to insert new items with Hibernate?
https://stackoverflow.com/questions/22472292/how-to-insert-new-items-with-hibernate
hibernate在数据库生成hibernate_sequence表问题
https://blog.csdn.net/danchaofan0534/article/details/53608832
本文介绍了Hibernate框架中ID生成策略的配置方法,特别是如何通过设置@GeneratedValue(strategy=GenerationType.IDENTITY)来利用数据库自身的自动增长功能,避免Hibernate尝试自行生成ID。此外还提供了解决Hibernate在数据库中创建hibernate_sequence表的问题。

389

被折叠的 条评论
为什么被折叠?



