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:
@Entity
public class Pessoa {
@Id
@GeneratedValue
@Column(name = "id_pessoa")
private int id;
@NotEmpty
@Column(name="nome_pessoa")
private String nome;
@Column(name = "sobrenome_pessoa")
private String sobenome;
@NotEmpty
@Column(name = "cpf_pessoa")
private String cpf;
@Column(name = "idade_pessoa")
private int idade;
@Column(name = "telefone_pessoa")
private int telefone;
@Email
@Column(name = "email_pessoa")
private String email;
@OneToOne
@JoinColumn(name = "id_usuario")
@Cascade(CascadeType.SAVE_UPDATE)
@ForeignKey(name = "fk_usuario")
private Usuario usario;
@OneToOne
@JoinColumn(name = "id_endereco")
@Cascade(CascadeType.SAVE_UPDATE)
@ForeignKey(name = "fk_endereco")
private Endereco endereco;
//getters e setters
Usuario:
public class Usuario {
@Id
@GeneratedValue
@Column(name = "id_usuario")
private int id;
@OneToOne
@JoinColumn(name = "id_pessoa")
@Cascade(CascadeType.SAVE_UPDATE)
@ForeignKey(name = "fk_pessoa")
private Pessoa pessoa;
@NotEmpty
private String usuario;
@NotEmpty
private String senha;
@NotEmpty
private String confrimarSenha;
//get e set
Endereco:
@Entity
public class Endereco {
@Id
@GeneratedValue
@Column(name = "id_endereco")
private int id;
private String logradouro;
private String numero;
private String complemeto;
private String cep;
private String bairro;
private String cidade;
private String estado;
@OneToMany
@JoinColumn(name = "id_pessoa")
@Cascade(CascadeType.SAVE_UPDATE)
@ForeignKey(name = "fk_pessoa")
private Pessoa pessoa;
// get e set...
Contatos:
@Entity
public class Contatos {
@Id
@GeneratedValue
private int id;
@ManyToMany
@JoinColumn(name = "id_pessoa")
@Cascade(CascadeType.SAVE_UPDATE)
@ForeignKey(name = "fk_pessoa")
private Pessoa pessoa;
@NotEmpty
private String nome;
private String telefone;
@Email
private String email;
private int idade;
private String endereco;
E a classe para gerar a tabela:
[code]
public class GeraTabela {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.configure();
SchemaExport se = new SchemaExport(cfg);
se.create(true, true);
}
}[/code]
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!?