Fork me on GitHub

关于 JPA PostgreSQL SERIAL BIGSERIAL 中使用 GenerationType.IDENTITY 批处理失效

Although convenient, and even suggested in many PostgreSQL book, the SERIAL and BIGSERIAL column types are not a very good choice when using JPA and Hibernate. Using a SEQUENCE generator is a better alternative since the identifier can be generated prior to executing the INSERT statement.

Behind the scenes, the SERIAL and BIGSERIAL column types use a database sequence anyway, so the only difference is that the SEQUENCE generator calls the sequence is a separate database roundtrip. However, this can also be optimized with the pooled and pooled-lo optimizers.

If the database server is close to the application servers and networking is fast, the extra database roundtrip is not going to be a performance bottleneck. For all these reasons, you should prefer using the SEQUENCE generator over IDENTITY no matter if you use PostgreSQL, Oracle or SQL Server.



Why To Avoid PostgreSQL (BIG)SERIAL In Batching Inserts Via Hibernate

PostgreSQL batch insert - jdbc reWriteBatchedInserts 批量写入 (copy,insert,begin commit,group commit)

posted @ 2021-06-06 14:20  花儿笑弯了腰  阅读(72)  评论(0编辑  收藏  举报