Hibernate - why use many-to-one to represent a one-to-one?

后端 未结 5 977
再見小時候
再見小時候 2020-11-28 06:40

I\'ve seen people use many-to-one mappings to represent one-to-one relationships. I\'ve also read this in a book by Gavin King and on articles.

For example, if a cu

5条回答
  •  北海茫月
    2020-11-28 07:16

    I would say the problem is fundamentally related to the object-relational impedance mismatch. To be able to relate the two object representations in a database, you need to have some sort of relationship between their tables. However, the database knows only the 1:N relationship: all the others are derived from it.

    With relational databases and object languages, it's up to the developer to find the least unnatural representation of the concept he/she wants to represent (in this case, a 1:1 relationship).

提交回复
热议问题