Mapeamento de uma coleção com chave composta!

0 respostas
Nicolas_Fernandes

E aí, galerinha do GUJ!
Tudo bem?

Tô com um problema, vejam se podem me ajudar, por favor! Eu tenho uma tabela PESSOAS, uma tabela TIPOSTELEFONES e uma tabela TELEFONES. Estão moldadas da seguinte forma:
CREATE TABLE PESSOAS (
ID BIGINT NOT NULL PRIMARY KEY,
...);

CREATE TABLE TIPOSTELEFONES (
...
);

CREATE TABLE TELEFONES (
PESSOA BIGINT NOT NULL,
TIPOTELEFONE BIGINT NOT NULL,
TELEFONE VARCHAR(10) NOT NULL,
FOREIGN KEY (PESSOA) REFERENCES PESSOAS(ID),
FOREIGN KEY (TIPOTELEFONE) REFERENCES TIPOSTELEFONES(ID),
PRIMARY KEY (PESSOA, TIPOTELEFONE));
Como podem ver, a tabela TELEFONES possui uma chave primária composta. Usando as Annotations do Hibernate, eu consegui as seguintes classes:
@Embeddable
public class TelefonePK implements Serializable {
    @Basic(optional = false)
    @Column(name = "pessoa", nullable = false)
    private long pessoa;
    @Basic(optional = false)
    @Column(name = "tipotelefone", nullable = false)
    private long tipotelefone;

    //...
}

@Entity
@Table(name = "telefones", schema = "dbo")
public class Telefone implements Serializable {
    
    @EmbeddedId
    protected TelefonePK ID;
    //...
}

@Entity
@Table(name = "pessoas", schema = "dbo")
public class Pessoa implements Serializable {
    //...
    // AQUI É O PROBLEMA QUE SURGIU!!!
    private List<Telefone> telefones;
}
Eis o problema: como fazer o mapeamento para esta coleção de telefones, sendo que eu possuo uma chave composta na tabela TELEFONES? Eu tentei da seguinte maneira:
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY, targetEntity=Telefone.class)
private List<Telefone> telefones;
Contudo, no momento em que a SessionFactory está sendo criada, me surge o seguinte erro:
Initial SessionFactory creation failed.org.hibernate.cfg.NotYetImplementedException: Collections having FK in secondary table

Alguma ideia de como posso resolver o problema?
Valeu, gente, fiquem com Deus! :D

Criado 15 de março de 2012
Respostas 0
Participantes 1