views:

30

answers:

1

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 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?

A: 

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

Ustaman Sangat