Should I use composite primary keys or not?

后端 未结 10 631
别那么骄傲
别那么骄傲 2020-12-03 07:28

There seems to only be 2nd class support for composite database keys in Java\'s JPA (via EmbeddedId or IdClass annotations). And when I read up on composite keys, regardless

10条回答
  •  半阙折子戏
    2020-12-03 08:05

    My general opinion is... no. don't use composite primary keys.

    They will typically complicate ORMs if you use them (ORMs sometimes go so far as to call composite primary keys "legacy behaviour") and generally if you're using multiple keys, one or more of them will tend to be natural rather than technical keys, which for me is the bigger problem: IMHO you should certainly favour technical primary keys.

    More on this in Database Development Mistakes Made by AppDevelopers.

提交回复
热议问题