Hibernate MappingException: Logical column name cannot be null
Asked Answered
T

3

10

Any idea about the below hibernate mapping exception. The below is the complete stack strace and there is no information on from which table this exception has occured.

org.hibernate.MappingException: Logical column name cannot be null
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:179)
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:121)
        at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667)
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:193)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
        at org.jboss.threads.JBossThread.run(JBossThread.java:320)
    Caused by: org.hibernate.MappingException: Logical column name cannot be null
        at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.getPhysicalColumnName(InFlightMetadataCollectorImpl.java:972)
        at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.getPhysicalColumnName(InFlightMetadataCollectorImpl.java:966)
        at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:681)
        at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:101)
        at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processEndOfQueue(InFlightMetadataCollectorImpl.java:1786)
        at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processFkSecondPassesInOrder(InFlightMetadataCollectorImpl.java:1730)
        at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1617)
        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)
        at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:161)
        ... 7 more

Any idea about the root-cause of this exception is welcomed.

Tengdin answered 25/11, 2016 at 12:0 Comment(2)
could you add your domain class and it mappings here, this error maybe for ManyToMany relations.Filiate
@RasoolGhafari thanks for the prompt reply. My ear contains multiple entity classes with ManyToMany relations, i couldn't find from which entity this error was thrown (stack strace also doesnt provide entity name) . Do you have any suggestion to identify the entity classTengdin
B
15

I was seeing the same error, but I've managed to fix it. I stumbled upon this in the documentation: "Many JPA implementations may throw seemingly inconsistent exceptions when not specifying referencedColumnName for every @JoinColumn annotation, which JPA requires (even if all referenced column names are equal to the ones in the referencing table)." Adding referencedColumnNames for every JoinColumn seemed to fix it for me.

And to help narrow down which class was giving me trouble, I set a breakpoint in org.hibernate.cfg.annotations.TableBinder::bindFk(), on line 682 where they call referencedColumn = buildingContext.getMetadataCollector().getPhysicalColumnName(table, referencedColumn); looking for when referencedColumn was empty or null.

Breadbasket answered 15/3, 2018 at 4:29 Comment(1)
Thanks @Breadbasket As per your instruction, I kept the debug point and checked when referencedColumnName is coming as null, and added referenceColumName for that.Absurd
O
3

Same answer as SnoopDougg.

With an additional information: I had a @ManyToMany with @JoinTable containing

  • joinColumns = {2 @Joincolumns}
  • inverseJoinColumns = {2 @Joincolumns}

If I express all 4 @JoinColumn without any referencedColumnName ==> OK.

If I set one referencedColumnName ==> Logical column name cannot be null.

Solution: put the referencedColumnName on all @JoinColumn

Orchestral answered 27/12, 2021 at 10:56 Comment(0)
C
0

The root-cause of this exception can be different. I my case:

@JoinColumnsOrFormulas(value = {
        @JoinColumnOrFormula(formula = @JoinFormula(value = "null"))
})
Coffey answered 15/11, 2021 at 11:7 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.