Hibernate use of PostgreSQL sequence does not affect sequence table

前端 未结 4 1564
挽巷
挽巷 2020-11-29 01:33

I\'ve configured Hibernate to use PostgreSQL sequence (via annotations) to generate values for primary key id column as follows:

@Id 
@Seque         


        
4条回答
  •  时光取名叫无心
    2020-11-29 02:11

    DO NOT USE GenerationType.SEQUENCE for Postgres sequences!

    It's completely counter-intuitive, but the Hibernate folks completely messed up on this. You must use GenerationType.AUTO or Hibernate will demolish your sequences if you have to restart/rebuild your DB. It's almost criminally negligent that they would allow this code to go into a production build, but the Hibernate team is rather famous for their bull-headed stances towards flatly-wrong positions (check out their position on LEFT JOINs, for instance).

提交回复
热议问题