Hi,
Any comments on how to solve this database design issue with JPA?
I have the entities District and Municipality. The District have a OneToMany relation with Municipality. So one district may have many Municipalities. Both District and Municipaliti have the fields id and name.
Now the proplem is that the name of the Municipality must be unique for each District. That is, it must be possible to have two Municipalities called "AAA" _but_ only in different districts. Thus the name filed of the Municipality cannot be unique.
Should I solve this by having a bidirectional relation between District and Municipality, so that the district_id (fk) in Municipality form a composite PK with the name field of the Municipality?
Or, should I solve this on the business logic layer. That is, each time I create a new Munciplaity, I have to check that there is not a municipality with the same name in the District where the Municipality is to be added?
Thanks,
Mattias
[Message sent by forum member 'nightzero' (nightzero)]
http://forums.java.net/jive/thread.jspa?messageID=337785