Org.hibernate.AnnotationException

Ola galera!!

quero fazer o seguinte:
uma Pessoa só pode ter UM Usuario e UM Endereco mas pode ter Varios contatos!!

Esta aki minhas classes:

Pessoa:

  1. @Entity  
   2. public class Pessoa {  
   3.       
   4.     @Id  
   5.     @GeneratedValue  
   6.     @Column(name = "id_pessoa")  
   7.     private int id;  
   8.       
   9.     @NotEmpty  
  10.     @Column(name="nome_pessoa")  
  11.     private String nome;  
  12.     @Column(name = "sobrenome_pessoa")  
  13.     private String sobenome;  
  14.     @NotEmpty  
  15.     @Column(name = "cpf_pessoa")  
  16.     private String cpf;  
  17.     @Column(name = "idade_pessoa")  
  18.     private int idade;  
  19.     @Column(name = "telefone_pessoa")  
  20.     private int telefone;  
  21.     @Email  
  22.     @Column(name = "email_pessoa")  
  23.     private String email;  
  24.       
  25.     @OneToOne  
  26.     @JoinColumn(name = "id_usuario")  
  27.     @Cascade(CascadeType.SAVE_UPDATE)  
  28.     @ForeignKey(name = "fk_usuario")  
  29.     private Usuario usario;  
  30.       
  31.     @OneToOne  
  32.     @JoinColumn(name = "id_endereco")  
  33.     @Cascade(CascadeType.SAVE_UPDATE)  
  34.     @ForeignKey(name = "fk_endereco")  
  35.     private Endereco endereco;  
  36.     //getters e setters  

Usuario:

[code]

  1. public class Usuario {
  2. @Id  
    
  3. @GeneratedValue  
    
  4. @Column(name = "id_usuario")  
    
  5. private int id;  
    
  6. @OneToOne  
    
  7. @JoinColumn(name = "id_pessoa")  
    
  8. @Cascade(CascadeType.SAVE_UPDATE)  
    
  9. @ForeignKey(name = "fk_pessoa")  
    
  10. private Pessoa pessoa;  
    
  11. @NotEmpty  
    
  12. private String usuario;  
    
  13. @NotEmpty  
    
  14. private String senha;  
    
  15. @NotEmpty  
    
  16. private String confrimarSenha;  
    
  17. //get e set  [/code]
    

Endereco:

[code]

  1. @Entity
  2. public class Endereco {
  3. @Id  
    
  4. @GeneratedValue  
    
  5. @Column(name = "id_endereco")  
    
  6. private int id;  
    
  7. private String logradouro;  
    
  8. private String numero;  
    
  9. private String complemeto;  
    
  10. private String cep;  
    
  11. private String bairro;  
    
  12. private String cidade;  
    
  13. private String estado;  
    
  14. @OneToMany  
    
  15. @JoinColumn(name = "id_pessoa")  
    
  16. @Cascade(CascadeType.SAVE_UPDATE)  
    
  17. @ForeignKey(name = "fk_pessoa")  
    
  18. private Pessoa pessoa;  
    
  19. // get e set...  [/code]
    

Contatos:

[code]

  1. @Entity
  2. public class Contatos {
  3. @Id  
    
  4. @GeneratedValue  
    
  5. private int id;  
    
  6. @ManyToMany  
    
  7. @JoinColumn(name = "id_pessoa")  
    
  8. @Cascade(CascadeType.SAVE_UPDATE)  
    
  9. @ForeignKey(name = "fk_pessoa")  
    
  10. private Pessoa pessoa;  
    
  11. @NotEmpty  
    
  12. private String nome;  
    
  13. private String telefone;  
    
  14. @Email  
    
  15. private String email;  
    
  16. private int idade;  
    
  17. private String endereco;  [/code]
    

E a classe para gerar a tabela:

1. public class GeraTabela { 2. 3. /** 4. * @param args 5. */ 6. public static void main(String[] args) { 7. // TODO Auto-generated method stub 8. 9. AnnotationConfiguration cfg = new AnnotationConfiguration(); 10. cfg.configure(); 11. 12. SchemaExport se = new SchemaExport(cfg); 13. se.create(true, true); 14. 15. } 16. 17. }

e da o seguinte error:
[color=red]
Exception in thread “main” org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: br.com.vetta.entidades.Endereco.pessoa
at org.hibernate.cfg.annotations.CollectionBinder.getCollectionBinder(CollectionBinder.java:266)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1448)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:754)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:803)
at org.hibernate.tool.hbm2ddl.SchemaExport.(SchemaExport.java:128)
at org.hibernate.tool.hbm2ddl.SchemaExport.(SchemaExport.java:91)
at br.com.vetta.teste.GeraTabela.main(GeraTabela.java:17)[/color]

Alguem poderia me informar pq ta dando este erro?
Estou meio confuso se fiz as assossiacoes corretamente!?

Na classe endereço tu informa que o mapeamento é um para um entre pessoa e endereco, e no endereco tu informa um um para muitos para pessoa, isso ja está errado, se for usar o mesmo relacionamento de forma bidirecional.

Mas no caso, o erro está no trecho @OneToMany @JoinColumn(name = "id_pessoa") @Cascade(CascadeType.SAVE_UPDATE) @ForeignKey(name = "fk_pessoa") private Pessoa pessoa;
pois o hibernate espera como atributo uma list, collection ou set de Pessoa, não um objeto Pessoa, pois esta sendo informado que é um para muitos, no caso, um endereco contem varias pessoas.
O mesmo erro se repete em @ManyToMany @JoinColumn(name = "id_pessoa") @Cascade(CascadeType.SAVE_UPDATE) @ForeignKey(name = "fk_pessoa") private Pessoa pessoa;

uma vez que está sendo esperado a list, collection ou set e está encontrando apenas um objeto.