-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: org.hibernate.MappingException: Unable to find column with l
PostPosted: Mon Dec 18, 2017 12:19 pm 
Newbie

Joined: Thu Nov 16, 2017 7:16 pm
Posts: 3
Hi
Can someone help me with this error.
This is about compositekeys, i have used netbeans to make my model trought my databases.
This is my class
ContactsPK
Code:
@Embeddable
public class ContactosPK implements Serializable {
    @Basic(optional = false)
    @Column(name = "idcontactos")
    private int idcontactos;
    @Basic(optional = false)
    @Column(name = "idCodigo")
    private int idCodigo;

    public ContactosPK() {
    }

    public ContactosPK(int idcontactos, int idCodigo) {
        this.idcontactos = idcontactos;
        this.idCodigo = idCodigo;
    }

    public int getIdcontactos() {
        return idcontactos;
    }

    public void setIdcontactos(int idcontactos) {
        this.idcontactos = idcontactos;
    }

    public int getIdCodigo() {
        return idCodigo;
    }

    public void setIdCodigo(int idCodigo) {
        this.idCodigo = idCodigo;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) idcontactos;
        hash += (int) idCodigo;
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ContactosPK)) {
            return false;
        }
        ContactosPK other = (ContactosPK) object;
        if (this.idcontactos != other.idcontactos) {
            return false;
        }
        if (this.idCodigo != other.idCodigo) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.ContactosPK[ idcontactos=" + idcontactos + ", idCodigo=" + idCodigo + " ]";
    }
   
}

And the related table Contacts

Code:
@Entity
@Table(name = "contactos")
@XmlRootElement
public class Contactos implements Serializable {
   
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    @Column(name="idcontactos")
    private ContactosPK contactosPK = new ContactosPK();
   

    private String nome;
    @Basic(optional = false)
    @Column(name = "Apelido")
    private String apelido;
    @Basic(optional = false)
    @Column(name = "CC")
    private String cc;
    @Basic(optional = false)
    @Column(name = "Nif")
    private int nif;
    @Basic(optional = false)
    @Column(name = "Telefone")
    private int telefone;
    @Basic(optional = false)
    @Column(name = "Email")
    private String email;
    @Basic(optional = false)
    @Column(name = "Endereco")
    private String endereco;
    @Basic(optional = false)
    @Column(name = "Localidade")
    private String localidade;
    @Basic(optional = false)
    @Column(name = "Concelho")
    private String concelho;
    @Column(name = "CP")
    private Integer cp;
    @Basic(optional = false)
    @Column(name = "Pais")
    private String pais;
    @Column(name = "Notas")
    private String notas;
    @Column(name = "Anexos")
    private String anexos;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idContacto1")
    private Collection<Atos> atosCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idContactos2")
    private Collection<Atos> atosCollection1;
    @JoinColumn(name = "idCodigo", referencedColumnName = "idCodigo", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Cpostais cpostais;

    public Contactos() {
    }

    public Contactos(ContactosPK contactosPK) {
        this.contactosPK = contactosPK;
    }

    public Contactos(ContactosPK contactosPK, String nome, String apelido, String cc, int nif, int telefone, String email, String endereco, String localidade, String concelho, String pais) {
        this.contactosPK = contactosPK;
        this.nome = nome;
        this.apelido = apelido;
        this.cc = cc;
        this.nif = nif;
        this.telefone = telefone;
        this.email = email;
        this.endereco = endereco;
        this.localidade = localidade;
        this.concelho = concelho;
        this.pais = pais;
    }

    public Contactos(int idcontactos, int idCodigo) {
        this.contactosPK = new ContactosPK(idcontactos, idCodigo);
    }

    public ContactosPK getContactosPK() {
        return contactosPK;
    }

    public void setContactosPK(ContactosPK contactosPK) {
        this.contactosPK = contactosPK;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getApelido() {
        return apelido;
    }

    public void setApelido(String apelido) {
        this.apelido = apelido;
    }

    public String getCc() {
        return cc;
    }

    public void setCc(String cc) {
        this.cc = cc;
    }

    public int getNif() {
        return nif;
    }

    public void setNif(int nif) {
        this.nif = nif;
    }

    public int getTelefone() {
        return telefone;
    }

    public void setTelefone(int telefone) {
        this.telefone = telefone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEndereco() {
        return endereco;
    }

    public void setEndereco(String endereco) {
        this.endereco = endereco;
    }

    public String getLocalidade() {
        return localidade;
    }

    public void setLocalidade(String localidade) {
        this.localidade = localidade;
    }

    public String getConcelho() {
        return concelho;
    }

    public void setConcelho(String concelho) {
        this.concelho = concelho;
    }

    public Integer getCp() {
        return cp;
    }

    public void setCp(Integer cp) {
        this.cp = cp;
    }

    public String getPais() {
        return pais;
    }

    public void setPais(String pais) {
        this.pais = pais;
    }

    public String getNotas() {
        return notas;
    }

    public void setNotas(String notas) {
        this.notas = notas;
    }

    public String getAnexos() {
        return anexos;
    }

    public void setAnexos(String anexos) {
        this.anexos = anexos;
    }

    @XmlTransient
    public Collection<Atos> getAtosCollection() {
        return atosCollection;
    }

    public void setAtosCollection(Collection<Atos> atosCollection) {
        this.atosCollection = atosCollection;
    }

    @XmlTransient
    public Collection<Atos> getAtosCollection1() {
        return atosCollection1;
    }

    public void setAtosCollection1(Collection<Atos> atosCollection1) {
        this.atosCollection1 = atosCollection1;
    }

    public Cpostais getCpostais() {
        return cpostais;
    }

    public void setCpostais(Cpostais cpostais) {
        this.cpostais = cpostais;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (contactosPK != null ? contactosPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Contactos)) {
            return false;
        }
        Contactos other = (Contactos) object;
        if ((this.contactosPK == null && other.contactosPK != null) || (this.contactosPK != null && !this.contactosPK.equals(other.contactosPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Contactos[ contactosPK=" + contactosPK + " ]";
    }
   
}


When i use the hql query
from Contactos

I have the following error

Code:
org.hibernate.MappingException: Unable to find column with logical name: contactosPK in org.hibernate.mapping.Table(contactos) and its related supertables and secondary tables
   at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:564)
   at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:258)
   at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:116)
   at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1596)
   at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1519)
   at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1420)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)



any help??

Thanks


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unable to find column with l
PostPosted: Wed Dec 20, 2017 5:38 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You need to remove @Column(name="idcontactos") from the identifier mapping.

Code:
@EmbeddedId
private ContactosPK contactosPK = new ContactosPK();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.