开发者

Multiple composite ids with relations or single field PKs

I've been dealing with composite id's and asked a few questions and I was recommended to replace my composite PK's with a single id column, and to control integrity with indexes... All of this related to the fact that mapping composite id's isn't that simple...

On the other side, some people encourage the usage of composite开发者_JAVA百科 id's that are accord to the domain model...

So I decided to ask: When will you encourage using composite PK's in your DB while using Hibernate?


I personally favor composite ids because they emerge out of the entity-relationships. However, Hibernate suggests the use of simple integer ids. But I think you don't have to choose one over the other.

You can have your composite id constituent fields to become a <natural-id> And have a private integral field in the class for hibernate to use as the id.

See http://docs.jboss.org/hibernate/stable/core/reference/en/html/mapping.html#mapping-declaration-naturalid

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜