Hibernate: MappingException

0 respostas
M

Olá amigos,

Estou desenvolvendo uma aplicação com o Hibernate, porém tenho uma tabela com chave composta dependente de outra tabela conforme ilustrado na figura abaixo.

O problema é que o mapeamento automático do hibernate no netbeans não cria o objeto e nem o mapeamento de tabelas igual a tabela Amigos da figura em anexo. Porém, reparei que ele cria um Set de atributos Id de amigos no objeto Usuarios.

Quando tento executar o banco de dados através do hibernate ele lança a seguitne exceção:
org.hibernate.MappingException: An association from the table amigos refers to an unmapped class: persistencia.hibernate.Usuarios.

Segue o mapeamento da tabela usuarios para que possam entender:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 09/11/2011 16:34:14 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
  <class catalog="bd_resti" name="persistencia.objetos.Usuarios" table="usuarios">
    <id name="idUsuario" type="java.lang.Integer">
      <column name="idUsuario"/>
      <generator class="identity"/>
    </id>
    <many-to-one class="persistencia.objetos.Fotos" fetch="select" name="fotos">
      <column name="idFotoPerfil"/>
    </many-to-one>
    <property name="apelido" type="string">
      <column length="45" name="apelido"/>
    </property>
    <property name="nome" type="string">
      <column length="200" name="nome" not-null="true"/>
    </property>
    <property name="email" type="string">
      <column length="100" name="email" not-null="true" unique="true"/>
    </property>
    <property name="senha" type="string">
      <column length="45" name="senha" not-null="true"/>
    </property>
    <property name="dataNascimento" type="date">
      <column length="10" name="dataNascimento" not-null="true"/>
    </property>
    <property name="religiao" type="string">
      <column length="100" name="religiao"/>
    </property>
    <property name="estadoCivil" type="string">
      <column length="100" name="estadoCivil"/>
    </property>
    <property name="sexo" type="string">
      <column length="8" name="sexo"/>
    </property>
    <property name="pais" type="string">
      <column length="100" name="pais"/>
    </property>
    <property name="estado" type="string">
      <column length="100" name="estado"/>
    </property>
    <property name="cidade" type="string">
      <column length="100" name="cidade"/>
    </property>
    <property name="msn" type="string">
      <column length="100" name="msn"/>
    </property>
    <property name="skype" type="string">
      <column length="100" name="skype"/>
    </property>
    <set inverse="false" name="eventoses" table="participantes_eventos">
      <key>
        <column name="idUsuario" not-null="true"/>
      </key>
      <many-to-many entity-name="persistencia.hibernate.Eventos">
        <column name="idEvento" not-null="true"/>
      </many-to-many>
    </set>
    <set inverse="true" name="mensagensesForIdUsuarioRemetente">
      <key>
        <column name="idUsuarioRemetente" not-null="true"/>
      </key>
      <one-to-many class="persistencia.objetos.Mensagens"/>
    </set>
    <set inverse="true" name="mensagensesForIdUsuarioDestinatario">
      <key>
        <column name="idUsuarioDestinatario" not-null="true"/>
      </key>
      <one-to-many class="persistencia.objetos.Mensagens"/>
    </set>
    <set inverse="false" name="usuariosesForIdUsuario2" table="amigos">
      <key>
        <column name="idUsuario1" not-null="true"/>
      </key>
      <many-to-many entity-name="persistencia.hibernate.Usuarios">
        <column name="idUsuario2" not-null="true"/>
      </many-to-many>
    </set>
    <set inverse="true" name="enqueteses" table="participantes_enquetes">
      <key>
        <column name="idUsuario" not-null="true"/>
      </key>
      <many-to-many entity-name="persistencia.hibernate.Enquetes">
        <column name="idEnquete" not-null="true"/>
      </many-to-many>
    </set>
    <set inverse="false" name="usuariosesForIdUsuario1" table="amigos">
      <key>
        <column name="idUsuario2" not-null="true"/>
      </key>
      <many-to-many entity-name="persistencia.hibernate.Usuarios">
        <column name="idUsuario1" not-null="true"/>
      </many-to-many>
    </set>
    <set inverse="true" name="comunidadeses" table="moderadores">
      <key>
        <column name="idUsuario" not-null="true"/>
      </key>
      <many-to-many entity-name="persistencia.hibernate.Comunidades">
        <column name="idComunidade" not-null="true"/>
      </many-to-many>
    </set>
    <set inverse="true" name="comunidadeses_1" table="participantes_comunidades">
      <key>
        <column name="idUsuario" not-null="true"/>
      </key>
      <many-to-many entity-name="persistencia.hibernate.Comunidades">
        <column name="idComunidade" not-null="true"/>
      </many-to-many>
    </set>
    <set inverse="true" name="curriculums">
      <key>
        <column name="idUsuario" not-null="true"/>
      </key>
      <one-to-many class="persistencia.objetos.Curriculum"/>
    </set>
    <set inverse="true" name="comunidadeses_2">
      <key>
        <column name="idUsuarioResponsavel" not-null="true"/>
      </key>
      <one-to-many class="persistencia.objetos.Comunidades"/>
    </set>
    <set inverse="true" name="enqueteses_1">
      <key>
        <column name="idUsuarioResponsavel" not-null="true"/>
      </key>
      <one-to-many class="persistencia.objetos.Enquetes"/>
    </set>
    <set inverse="true" name="eventoses_1">
      <key>
        <column name="idUsuario" not-null="true"/>
      </key>
      <one-to-many class="persistencia.objetos.Eventos"/>
    </set>
    <set inverse="true" name="postagenses">
      <key>
        <column name="idUsuario" not-null="true"/>
      </key>
      <one-to-many class="persistencia.objetos.Postagens"/>
    </set>
  </class>
</hibernate-mapping>
package persistencia.objetos;
// Generated 09/11/2011 16:34:10 by Hibernate Tools 3.2.1.GA


import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * Usuarios generated by hbm2java
 */
public class Usuarios  implements java.io.Serializable {


     private Integer idUsuario;
     private Fotos fotos;
     private String apelido;
     private String nome;
     private String email;
     private String senha;
     private Date dataNascimento;
     private String religiao;
     private String estadoCivil;
     private String sexo;
     private String pais;
     private String estado;
     private String cidade;
     private String msn;
     private String skype;
     private Set eventoses = new HashSet(0);
     private Set mensagensesForIdUsuarioRemetente = new HashSet(0);
     private Set mensagensesForIdUsuarioDestinatario = new HashSet(0);
     private Set usuariosesForIdUsuario2 = new HashSet(0);
     private Set enqueteses = new HashSet(0);
     private Set usuariosesForIdUsuario1 = new HashSet(0);
     private Set comunidadeses = new HashSet(0);
     private Set comunidadeses_1 = new HashSet(0);
     private Set curriculums = new HashSet(0);
     private Set comunidadeses_2 = new HashSet(0);
     private Set enqueteses_1 = new HashSet(0);
     private Set eventoses_1 = new HashSet(0);
     private Set postagenses = new HashSet(0);

    public Usuarios() {
    }

	
    public Usuarios(String nome, String email, String senha, Date dataNascimento) {
        this.nome = nome;
        this.email = email;
        this.senha = senha;
        this.dataNascimento = dataNascimento;
    }
    public Usuarios(Fotos fotos, String apelido, String nome, String email,
 String senha, Date dataNascimento, String religiao, String estadoCivil, String sexo, String pais, String estado, String cidade, String msn, String skype, 
Set eventoses, Set mensagensesForIdUsuarioRemetente, Set mensagensesForIdUsuarioDestinatario, Set usuariosesForIdUsuario2, Set enqueteses, Set usuariosesForIdUsuario1, Set comunidadeses, 
Set comunidadeses_1, Set curriculums, Set comunidadeses_2, Set enqueteses_1, Set eventoses_1, Set postagenses) {
       this.fotos = fotos;
       this.apelido = apelido;
       this.nome = nome;
       this.email = email;
       this.senha = senha;
       this.dataNascimento = dataNascimento;
       this.religiao = religiao;
       this.estadoCivil = estadoCivil;
       this.sexo = sexo;
       this.pais = pais;
       this.estado = estado;
       this.cidade = cidade;
       this.msn = msn;
       this.skype = skype;
       this.eventoses = eventoses;
       this.mensagensesForIdUsuarioRemetente = mensagensesForIdUsuarioRemetente;
       this.mensagensesForIdUsuarioDestinatario = mensagensesForIdUsuarioDestinatario;
       this.usuariosesForIdUsuario2 = usuariosesForIdUsuario2;
       this.enqueteses = enqueteses;
       this.usuariosesForIdUsuario1 = usuariosesForIdUsuario1;
       this.comunidadeses = comunidadeses;
       this.comunidadeses_1 = comunidadeses_1;
       this.curriculums = curriculums;
       this.comunidadeses_2 = comunidadeses_2;
       this.enqueteses_1 = enqueteses_1;
       this.eventoses_1 = eventoses_1;
       this.postagenses = postagenses;
    }
   
    public Integer getIdUsuario() {
        return this.idUsuario;
    }
    
    public void setIdUsuario(Integer idUsuario) {
        this.idUsuario = idUsuario;
    }
    public Fotos getFotos() {
        return this.fotos;
    }
    
    public void setFotos(Fotos fotos) {
        this.fotos = fotos;
    }
    public String getApelido() {
        return this.apelido;
    }
    
    public void setApelido(String apelido) {
        this.apelido = apelido;
    }
    public String getNome() {
        return this.nome;
    }
    
    public void setNome(String nome) {
        this.nome = nome;
    }
    public String getEmail() {
        return this.email;
    }
    
    public void setEmail(String email) {
        this.email = email;
    }
    public String getSenha() {
        return this.senha;
    }
    
    public void setSenha(String senha) {
        this.senha = senha;
    }
    public Date getDataNascimento() {
        return this.dataNascimento;
    }
    
    public void setDataNascimento(Date dataNascimento) {
        this.dataNascimento = dataNascimento;
    }
    public String getReligiao() {
        return this.religiao;
    }
    
    public void setReligiao(String religiao) {
        this.religiao = religiao;
    }
    public String getEstadoCivil() {
        return this.estadoCivil;
    }
    
    public void setEstadoCivil(String estadoCivil) {
        this.estadoCivil = estadoCivil;
    }
    public String getSexo() {
        return this.sexo;
    }
    
    public void setSexo(String sexo) {
        this.sexo = sexo;
    }
    public String getPais() {
        return this.pais;
    }
    
    public void setPais(String pais) {
        this.pais = pais;
    }
    public String getEstado() {
        return this.estado;
    }
    
    public void setEstado(String estado) {
        this.estado = estado;
    }
    public String getCidade() {
        return this.cidade;
    }
    
    public void setCidade(String cidade) {
        this.cidade = cidade;
    }
    public String getMsn() {
        return this.msn;
    }
    
    public void setMsn(String msn) {
        this.msn = msn;
    }
    public String getSkype() {
        return this.skype;
    }
    
    public void setSkype(String skype) {
        this.skype = skype;
    }
    public Set getEventoses() {
        return this.eventoses;
    }
    
    public void setEventoses(Set eventoses) {
        this.eventoses = eventoses;
    }
    public Set getMensagensesForIdUsuarioRemetente() {
        return this.mensagensesForIdUsuarioRemetente;
    }
    
    public void setMensagensesForIdUsuarioRemetente(Set mensagensesForIdUsuarioRemetente) {
        this.mensagensesForIdUsuarioRemetente = mensagensesForIdUsuarioRemetente;
    }
    public Set getMensagensesForIdUsuarioDestinatario() {
        return this.mensagensesForIdUsuarioDestinatario;
    }
    
    public void setMensagensesForIdUsuarioDestinatario(Set mensagensesForIdUsuarioDestinatario) {
        this.mensagensesForIdUsuarioDestinatario = mensagensesForIdUsuarioDestinatario;
    }
    public Set getUsuariosesForIdUsuario2() {
        return this.usuariosesForIdUsuario2;
    }
    
    public void setUsuariosesForIdUsuario2(Set usuariosesForIdUsuario2) {
        this.usuariosesForIdUsuario2 = usuariosesForIdUsuario2;
    }
    public Set getEnqueteses() {
        return this.enqueteses;
    }
    
    public void setEnqueteses(Set enqueteses) {
        this.enqueteses = enqueteses;
    }
    public Set getUsuariosesForIdUsuario1() {
        return this.usuariosesForIdUsuario1;
    }
    
    public void setUsuariosesForIdUsuario1(Set usuariosesForIdUsuario1) {
        this.usuariosesForIdUsuario1 = usuariosesForIdUsuario1;
    }
    public Set getComunidadeses() {
        return this.comunidadeses;
    }
    
    public void setComunidadeses(Set comunidadeses) {
        this.comunidadeses = comunidadeses;
    }
    public Set getComunidadeses_1() {
        return this.comunidadeses_1;
    }
    
    public void setComunidadeses_1(Set comunidadeses_1) {
        this.comunidadeses_1 = comunidadeses_1;
    }
    public Set getCurriculums() {
        return this.curriculums;
    }
    
    public void setCurriculums(Set curriculums) {
        this.curriculums = curriculums;
    }
    public Set getComunidadeses_2() {
        return this.comunidadeses_2;
    }
    
    public void setComunidadeses_2(Set comunidadeses_2) {
        this.comunidadeses_2 = comunidadeses_2;
    }
    public Set getEnqueteses_1() {
        return this.enqueteses_1;
    }
    
    public void setEnqueteses_1(Set enqueteses_1) {
        this.enqueteses_1 = enqueteses_1;
    }
    public Set getEventoses_1() {
        return this.eventoses_1;
    }
    
    public void setEventoses_1(Set eventoses_1) {
        this.eventoses_1 = eventoses_1;
    }
    public Set getPostagenses() {
        return this.postagenses;
    }
    
    public void setPostagenses(Set postagenses) {
        this.postagenses = postagenses;
    }

}

Conto com a ajuda de vocês, obrigado.

Criado 10 de novembro de 2011
Respostas 0
Participantes 1