If it's possible, I would change the structure of the table to something like this:
CREATE TABLE `phones`
(
`id` integer (10) NOT NULL AUTO_INCREMENT ,
`idCustomer` integer (10),
`idEmployee` integer (10),
`idUser` integer (10),
`tipo` varchar (50),
`numero` varchar (200),
PRIMARY KEY (`id`)
)
That's a different way of implementing an arc (a relationship to exclusively one of several tables). The advantage of implementing it the way I suggest is you can create foreign keys to the related tables instead of validating their existence in the application. Mapping that table in JPA/Hibernate would also be natural.
The exclusivity of the relationship can be enforced by a constraint that checks that only one of the idSomething fields is not null.
The disadvantage of this implementation is that you need to add a new field and redefine the constraint every time you want to add a new table in the arc relationship.
I hope that helps.
[Message sent by forum member 'mpeccorini' (mpeccorini)]
http://forums.java.net/jive/thread.jspa?messageID=322703