users@glassfish.java.net

Re: Entity design

From: Aleksandras Novikovas <an_at_systemtier.com>
Date: Wed, 18 Mar 2009 21:26:07 +0200

Hi,

Just add UNIQUE index on Municipality (district_id, name) in database.

-
Aleksandras Novikovas



On Wed, 2009-03-18 at 12:01 -0700, glassfish_at_javadesktop.org wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>