users@glassfish.java.net

Re: How can I implement this relationship

From: <glassfish_at_javadesktop.org>
Date: Sun, 21 Dec 2008 12:45:50 PST

@ManyToOne
@JoinColumns({
@JoinColumn(name="idEntidad", referencedColumnName="ID"),
@JoinColumn(name=""entidad", referencedColumnName="ID") <------------------ Incorrect
})
private Customer customer;
}

The second JoinColumn is incorrect. But you could add a field (say, 'type') to the customer table as follows:

create table customer(
id integer primary key,
type varchar(16) default 'Customer' , <---------------- New Addition
...
)

AND

CREATE TABLE `phones` (
        `id` integer (10) NOT NULL AUTO_INCREMENT ,
        `entidad` varchar (50),
        `idEntidad` integer (10),
        `tipo` varchar (50),
        `numero` varchar (200),
        PRIMARY KEY (`id`),
        
         UNIQUE (entidad, idEntidad) <---------------- New Addition
)

Then you could have:
 
@ManyToOne
@JoinColumns({
@JoinColumn(name="idEntidad", referencedColumnName="ID"),
@JoinColumn(name=""entidad", referencedColumnName="TYPE")
})
private Customer customer;
}
[i][/i]
[Message sent by forum member 'nuffsaidx' (nuffsaidx)]

http://forums.java.net/jive/thread.jspa?messageID=322867