Should I use composite primary keys or not?

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

    It's a religious thing. I use natural keys and shun surrogates. I have no problem with composite keys either in theory or in practice.

    Only the most trivial logical model would involve no composite keys. Call me lazy but I see no need to complicate the data model by introducing surrogates into the physical model on implementation. Sure, I'd consider one on a table if performance issues were found but I take the same approach as for denormalization i.e. as a last resort. Habitually using surrogates amounts to premature optimization, IMO.

提交回复
热议问题