Sorry for my bad english.
I've two classes: endereco and pessoa
There's a one-to-one relationship between both. The primary key of person is transfered to adress as foreign key and it's foreign key is the primary key to.
The DDL of tables are the follow:
CREATE TABLE pessoa (
CODIGO_PESS NUMBER(6,0) NOT NULL,
NOME VARCHAR2(40),
TELEFONE VARCHAR2(14),
IDADE NUMBER(3,0)
);
ALTER TABLE pessoa ADD CONSTRAINT pk_pess PRIMARY KEY ( CODIGO_PESS );
CREATE TABLE endereco (
CODIGO_PESS NUMBER(6,0) NOT NULL,
CODIGO_AREA NUMBER(6,0) NOT NULL,
RUA VARCHAR2(40),
NUMERO NUMBER(5,0),
BAIRRO VARCHAR2(25),
CIDADE VARCHAR2(25),
ESTADO VARCHAR2(2),
CEP VARCHAR2(9)
);
ALTER TABLE endereco ADD CONSTRAINT pk_ende PRIMARY KEY ( CODIGO_PESS );
ALTER TABLE endereco ADD CONSTRAINT fk_ende_pess01 FOREIGN KEY ( CODIGO_PESS ) REFERENCES pessoa ( CODIGO_PESS );
ALTER TABLE endereco ADD CONSTRAINT fk_ende_area02 FOREIGN KEY ( CODIGO_AREA ) REFERENCES area ( CODIGO_AREA );
My endereco.java class is the follow:
public class Endereco {
private Pessoa pessoa;
private Vendedor vendedor;
private Area area;
private String rua;
private int numero;
private String bairro;
private String cidade;
private String estado;
private String cep;
public Endereco() {
super();
}
public Pessoa getPessoa() {
return cliente;
}
public void setPessoa(Pessoa pessoa) {
this.pessoa = pessoa;
}
...
}
How should be the endereco.hbm.xml file once the id column is in another class (pessoa)?
Should I have both the atribute "int codigoPess" and "Pessoa pessoa" in the endereco.java class and map the id to codigoPess atribute of endereco and a relationship one-to-one to pessoa atribute or it will be a redundance information?
|