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
1. public class Usuario {
2.
3. @Id
4. @GeneratedValue
5. @Column(name = "id_usuario")
6. private int id;
7.
8. @OneToOne
9. @JoinColumn(name = "id_pessoa")
10. @Cascade(CascadeType.SAVE_UPDATE)
11. @ForeignKey(name = "fk_pessoa")
12. private Pessoa pessoa;
13.
14. @NotEmpty
15. private String usuario;
16. @NotEmpty
17. private String senha;
18. @NotEmpty
19. private String confrimarSenha;
20. //get e set
1. @Entity
2. public class Endereco {
3.
4. @Id
5. @GeneratedValue
6. @Column(name = "id_endereco")
7. private int id;
8.
9. private String logradouro;
10. private String numero;
11. private String complemeto;
12. private String cep;
13. private String bairro;
14. private String cidade;
15. private String estado;
16.
17. @OneToMany
18. @JoinColumn(name = "id_pessoa")
19. @Cascade(CascadeType.SAVE_UPDATE)
20. @ForeignKey(name = "fk_pessoa")
21. private Pessoa pessoa;
22. // get e set...
1. @Entity
2. public class Contatos {
3.
4. @Id
5. @GeneratedValue
6. private int id;
7.
8. @ManyToMany
9. @JoinColumn(name = "id_pessoa")
10. @Cascade(CascadeType.SAVE_UPDATE)
11. @ForeignKey(name = "fk_pessoa")
12. private Pessoa pessoa;
13. @NotEmpty
14. private String nome;
15. private String telefone;
16. @Email
17. private String email;
18. private int idade;
19. private String endereco;
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.
at org.hibernate.tool.hbm2ddl.SchemaExport.
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!?