Should I use composite primary keys or not?

后端 未结 10 636
别那么骄傲
别那么骄傲 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:02

    Religious wars have been, and still are, going on on this subject.

    OO people have this zealous thing about "identity", and will tell you that the only thing that matters is the ability for you to "identify" "real-life objects" inside your programs, and that composite, "real-life" keys will only get you into trouble when trying to achieve that goal.

    Data people have this thing about "uniqueness" that is perceived as "zealous" by the OO side, and will tell you that the only thing that matters is that if the business tells you that the combination of (values for) attribute X and attribute Y must be unique, then it is your job to see to it that the database enforces this business rule of uniqueness of the combined X+Y.

    How you want your question answered is just a matter of which religion you prefer. My personal religion is the Data one. That religion has proven to be able to survive any hype and trend ever since 1969.

提交回复
热议问题