# How to fix “Unable to find column with logical name” in Java, Hibernate

**URL:** <https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174>\
**Category:** Hibernate ORM\
**Created:** [January 30, 2019, 5:48pm UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174 "2019-01-30T17:48:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveDarkLion](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/davedarklion/32/459_2.png) [@DaveDarkLion](https://discourse.hibernate.org/u/DaveDarkLion)\
**Post date:** [January 30, 2019, 5:48pm UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174/1 "2019-01-30T17:48:09Z")

</div>

I’m getting the error “Unable to find column with logical name: dniNumeros in org.hibernate.mapping.Table(alumno) and its related supertables and secondary tables” when using IdClass

I have tried using an EmbeddedId instead and I’m getting the same error. The column obviously exists in my database, because the code works perfectly fine when I remove the IdClass line from it

```auto
@Entity
@Table(name="dificultadalumnoejercicio")
@IdClass(DificultadAlumnoEjercicioPK.class)
public class DificultadAlumnoEjercicio implements Serializable {

    private static final long serialVersionUID = -111454640507305257L;

    @Id
    @ManyToOne(cascade=CascadeType.MERGE)
    @JoinColumns ({
    @JoinColumn(name="alumnoDNINumeros", referencedColumnName="dniNumeros"),
    @JoinColumn(name="alumnoDNILetra", referencedColumnName="dniLetra")
    })
    private Alumno alumno;

    @Id
    @OneToOne(cascade=CascadeType.MERGE)
    @JoinColumn(name="ejercicioID", referencedColumnName="id")
    private Ejercicio ejercicio;

    @ManyToOne(cascade=CascadeType.MERGE)
    @JoinColumn(name="dificultadID", referencedColumnName="id")
    private Dificultad dificultad;

    // Constructors / Getters / Setters

}

```

And here’s my IdClass

```auto
@Embeddable
public class DificultadAlumnoEjercicioPK implements Serializable {

    private static final long serialVersionUID = 5559503979252689702L;

    public Alumno alumno;

    public Ejercicio ejercicio;

    // Constructors / Getters / Setters

}

```

Here is my database code:

```auto
CREATE TABLE `dificultadAlumnoEjercicio` (

    `alumnoDNINumeros` CHAR(8),
    `alumnoDNILetra` CHAR,
    `ejercicioID` INT,
    `dificultadID` INT NOT NULL,

    PRIMARY KEY (alumnoDNINumeros, alumnoDNILetra, ejercicioID),
    FOREIGN KEY (alumnoDNINumeros, alumnoDNILetra) REFERENCES alumno(dniNumeros, dniLetra),
    FOREIGN KEY (dificultadID) REFERENCES dificultad(id),
    FOREIGN KEY (ejercicioID) REFERENCES ejercicio(id)

);

CREATE TABLE `alumno` (

    `dniNumeros` CHAR(8),
    `dniLetra` CHAR,

    PRIMARY KEY (dniNumeros, dniLetra),
    FOREIGN KEY (dniNumeros, dniLetra) REFERENCES persona(dniNumeros, dniLetra)

);

```

I have already asked in Stackoverflow and nobody answered, and all my friends that are knowledgeable of Hibernate and they all say my code should work, so I don’t know where to look for the answer

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [January 30, 2019, 8:19pm UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174/2 "2019-01-30T20:19:10Z")

</div>

If you can replicate it with [this test case template](http://in.relation.to/2016/01/14/hibernate-jpa-test-case-template/) and you think the mapping is supposed to work, then you should open a new Jira issue.

---

<div class="post-metadata">

**Author:** ![DaveDarkLion](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/davedarklion/32/459_2.png) [@DaveDarkLion](https://discourse.hibernate.org/u/DaveDarkLion)\
**Post date:** [January 31, 2019, 5:45pm UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174/3 "2019-01-31T17:45:09Z")

</div>

I have replicated the error in the test case template and in the process realized that it only happens when I have more than one @Id field in the DificultadAlumnoEjercicio class. If I were to remove the @Id from Ejercicio ejercicio then it would work. After this, I’m gonna assume this is some kind of internal hibernate bug and try to adapt my code so that I can do what I need. Thanks for the reply

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [January 31, 2019, 5:59pm UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174/4 "2019-01-31T17:59:19Z")

</div>

If you assume it’s a bug, why don’t you create a Jira issue?

---

<div class="post-metadata">

**Author:** ![DaveDarkLion](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/davedarklion/32/459_2.png) [@DaveDarkLion](https://discourse.hibernate.org/u/DaveDarkLion)\
**Post date:** [January 31, 2019, 6:03pm UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174/5 "2019-01-31T18:03:08Z")

</div>

Because it’s a college project, I’m not working as part of a team

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [February 1, 2019, 8:18am UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174/6 "2019-02-01T08:18:09Z")

</div>

I was talking about the [Hibernate Jira](https://hibernate.atlassian.net).

---

<div class="post-metadata">

**Author:** ![DaveDarkLion](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/davedarklion/32/459_2.png) [@DaveDarkLion](https://discourse.hibernate.org/u/DaveDarkLion)\
**Post date:** [February 1, 2019, 12:29pm UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174/7 "2019-02-01T12:29:23Z")

</div>

Oh, my bad, I thought you meant to report the bug to my organization or something.

Ok, so, here’s the thing, I got two friends of mine who hadn’t looked at the code before and they managed to fix it, but I don’t know if this is the correct way of working with Hibernate, and they’re not sure either.

What we did was explicitly declare all the table columns where needed, like

```auto

@Id 
@Column(insertable = false, updatable = false)
private String alumnoDNI;

```

or

```auto
@Id
@Column(insertable = false, updatable = false)
private int ejercicioId;

```

in addition of the implicit declaration of those columns that already was in the code through @JoinColumn annotations, and then we assign their value in the constructor, for example:

```auto
public DificultadAlumnoEjercicio(Alumno alumno, Ejercicio ejercicio, Dificultad dificultad) {
	
 super();
		
	this.alumno = alumno;
	this.ejercicio = ejercicio;
	this.dificultad = dificultad;
		
	this.alumnoDNI = alumno.getDni();
	this.ejercicioId = ejercicio.getId();
		
}

```

This works, but the fact that the program was working before without the IdClass line or without more than one Id makes me wonder if this is still abug (because it’s very inconsistent and the things that make the code work don’t make much sense from my point of view), so I’m unsure whether to report it as such. What do you think?

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [February 1, 2019, 1:24pm UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174/8 "2019-02-01T13:24:21Z")

</div>

It’s hard tell whether it’s a bug or not unless I see all the code. Therefore, if you can replicate it, I will take a look at it.

---

<div class="post-metadata">

**Author:** ![DaveDarkLion](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/davedarklion/32/459_2.png) [@DaveDarkLion](https://discourse.hibernate.org/u/DaveDarkLion)\
**Post date:** [February 1, 2019, 3:28pm UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174/9 "2019-02-01T15:28:14Z")

</div>

Alright, here’s what I made. I tried to replicate the error I was having in the beginning, without the latest changes that I made to my project so you can see what I mean by it “working inconsistently”

What’s in the link is the script to create the db plus the project. If you try to run it as it is, you’ll get the error I was getting, “unable to find column with logical name…”

Try deleting the

```auto
@IdClass(ErrorPK.class)

```

line and it’ll work perfectly, and you’ll be able to add and delete from the db. This also happens if you delete the Id annotation from either alumn or randomIdColumn in Error.class. This is why I say this might be a bug, because when I delete code that has nothing to do with how the column is named or how it’s created, it suddenly works.

Link: [https://github.com/DaveDarkLion/HibernateTest](https://github.com/DaveDarkLion/HibernateTest)

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [February 1, 2019, 4:06pm UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174/10 "2019-02-01T16:06:22Z")

</div>

1. `Alumn` should use `@MapsId`. Check out [this article](https://vladmihalcea.com/the-best-way-to-map-a-onetoone-relationship-with-jpa-and-hibernate/) for more details.
2. `ErrorPK` should not use `@Embeddable` since it’s using `@IdClass` instead.

---

<div class="post-metadata">

**Author:** ![DaveDarkLion](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/davedarklion/32/459_2.png) [@DaveDarkLion](https://discourse.hibernate.org/u/DaveDarkLion)\
**Post date:** [February 1, 2019, 5:52pm UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174/11 "2019-02-01T17:52:25Z")

</div>

Thanks, I’ll change my code and see how it goes

---

<div class="post-metadata">

**Author:** ![MDS\_Productions](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mds_productions/32/522_2.png) [@MDS\_Productions](https://discourse.hibernate.org/u/MDS_Productions)\
**Post date:** [March 25, 2019, 5:42am UTC](https://discourse.hibernate.org/t/how-to-fix-unable-to-find-column-with-logical-name-in-java-hibernate/2174/12 "2019-03-25T05:42:10Z")

</div>

very useful conversations.

[https://wespm.com/category/notification/](https://wespm.com/category/notification/)
