关于以下休眠映射异常的任何想法。以下是完整的堆栈strace,并且没有关于从哪个表发生此异常的信息。
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
欢迎对此异常的根本原因有任何想法。
最佳答案
我看到了同样的错误,但已设法解决了。我在documentation中偶然发现了这个问题:“许多JPA实现可能在未为每个@JoinColumn批注指定指定referencedColumnName时抛出看似不一致的异常,这是JPA要求的(即使所有引用的列名都等于引用表中的列名)。”为每个JoinColumn添加referencedColumnNames似乎为我解决了。
为了帮助缩小哪个类给我带来的麻烦,我在第682行的org.hibernate.cfg.annotations.TableBinder::bindFk()中设置了一个断点,它们在调用referencedColumn = buildingContext.getMetadataCollector().getPhysicalColumnName(table, referencedColumn);
时查找referencedColumn
为空或空。