-->
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
PostPosted: Wed Nov 07, 2012 12:59 pm 
Newbie

Joined: Mon Jul 26, 2010 9:58 am
Posts: 6
I have this TABLES:

1.- PARTICIPANTE


Code:
CREATE TABLE participante (
       id_participa    SMALLINT NOT NULL,
       nasi            INTEGER NOT NULL,
       PRIMARY KEY(id_participa,nasi),
       FOREIGN KEY(nasi) REFERENCES persona(nasi)
    )


2.- PERSONA

Code:
CREATE TABLE persona (
        nasi         INTEGER NOT NULL,
       PRIMARY KEY(nasi)
    )


3.- CITA

Code:
CREATE TABLE cita (
       id_participa   SMALLINT NOT NULL,
       nasi           INTEGER NOT NULL,
       idcita         INTEGER NOT NULL,
       PRIMARY KEY(id_participa,idcita,nasi),
       FOREIGN KEY(id_participa, nasi)   REFERENCES participante(id_participa, nasi)
    )


4.- FORMULARIO

Code:
CREATE TABLE formulario (
          id_participa       SMALLINT NOT NULL,
          nasi               INTEGER NOT NULL,
          idcita             INTEGER NOT NULL,
          PRIMARY KEY(id_participa,idcita,nasi),
          FOREIGN KEY(id_participa, nasi, idcita) REFERENCES cita(id_participa, nasi, idcita)
       )


(among other fields, I just show you the ones that are involved in the problem)

and here are the ENTITIES:

1.- PARTICIPANTE

Code:
@Entity
    @Table(name = "participante")
    public class Participante implements Serializable {
   
       private static final long serialVersionUID = 1L;
       @Id
       @Column(name = "id_participa")
       private Integer idParticipante;
       @Id
       @OneToOne
       @JoinColumn(name = "nasi")
       private Persona persona;


2.- PERSONA

Code:
@Entity
    @Table(name = "persona")
    public class Persona implements Serializable {
   
       private static final long serialVersionUID = 1L;
       @Id
       @Column(name = "nasi")
       private Integer nasi;


3.- CITA

Code:
@Entity
    @Table(name = "cita")
    public class Cita implements Serializable {
   
       private static final long serialVersionUID = 1L;
       @Id
       @Column(name = "idcita")
       private Integer idCita;
       @Id
       @ManyToOne
       @JoinColumns({
             @JoinColumn(name = "id_participa", referencedColumnName = "id_participa"),
             @JoinColumn(name = "nasi", referencedColumnName = "nasi") })
       private Participante participante;


4.- FORMULARIO

Code:
@Entity
    @Table(name = "formulario")
    public class Formulario implements Serializable {
   
       private static final long serialVersionUID = 1L;
       @Id
       @OneToOne
       @JoinColumns({
             @JoinColumn(name = "id_participa", referencedColumnName = "id_participa"),
             @JoinColumn(name = "nasi", referencedColumnName = "nasi"),
             @JoinColumn(name = "idcita", referencedColumnName = "idcita") })
       private Cita cita;



And when I try to start the server I got this exception:

Code:
org.hibernate.MappingException: Unable to find column with logical name: nasi in participante
       at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:575)


EDIT: If I delete the "referencedColumnName" attributes I get:

Code:
Caused by: org.hibernate.AnnotationException: A Foreign key refering es.sergas.sicco.modelo.datos.dominio.participante.Participante from es.myapp.modelo.datos.dominio.cita.Cita has the wrong number of column. should be 1
    at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:432)
    at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:117)
    at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1514)
    at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1437)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1355)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:242)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:372)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:357)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
    ... 73 more


Aaaaand if I split Participante properties in two like this:

Code:
@Id
    @ManyToOne
    @JoinColumn(name = "id_participa")
    private Participante participanteId;
    @Id
    @ManyToOne
    @JoinColumn(name = "nasi")
    private Participante participanteNasi;

I get another exception:

Code:
Caused by: org.hibernate.MappingException: Foreign key (FK2EFB9FBA36C41465:cita [id_participa])) must have same number of columns as the referenced primary key (participante [nasi,id_participa])
    at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:110)
    at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:93)
    at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1703)
    at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1626)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1359)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:242)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:372)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:357)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
    ... 73 more


Top
 Profile  
 
 Post subject: Re: org.hibernate.MappingException: Unable to find column with
PostPosted: Thu Nov 08, 2012 12:53 pm 
Newbie

Joined: Mon Jul 26, 2010 9:58 am
Posts: 6
Well, if I create auxiliary PK classes it works...

For example:

Code:
@Embeddable
public class CitaPK implements Serializable{

    private static final long serialVersionUID = 1L;
    @ManyToOne
    @JoinColumns({
            @JoinColumn(name = "id_participa", referencedColumnName = "id_participa"),
            @JoinColumn(name = "nasi", referencedColumnName = "nasi") })
    private Participante participante;
    @Column(name = "idcita", columnDefinition="smallint")
    private Integer idCita;


And then in Cita class:

Code:
@Entity
@Table(name = "sicco_citas")
public class Cita implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    private CitaPK citaPK;

http://docs.jboss.org/hibernate/stable/annotations/reference/en/html/entity.html#d0e2177


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.