I’m upgrading one of our ancient projects to Hibernate 6.0 (from 4.3), and now I’m getting UnknownTableReferenceException when I create the SessionFactory. Our mappings are in .hbm.xml files, and the relevant parts look like this:
Materials.hbm.xml:
From what I understand, the different names used (FURNACE_ID vs UNIT_ID) should not be a problem, because Hibernate knows that FURNACE_ID is a foreign key to a SmeltingPlant. But I get
java.lang.IllegalStateException: Could not resolve table reference ...
Caused by: org.hibernate.sql.ast.tree.from.UnknownTableReferenceException: Unable to determine TableReference (SMELT_FURNACE_TABLE) for `treat(treat(SmeltFurnace as GenericFurnace).electricitySecondary.inheritance.ancestor as HotMetalMaterial).furnace.{id}`
This seems to be an very rare exception, since the only hits I get on Google for it is its listing in Hibernate API reference.
Some new information. After looking at the database, it turns out that electricitySecondary (that is, the foreign key referencing a Material) is null. This has not, however, been a problem before, and in the hbm.xml we have set
so it should just smack a null into the reference field in the java class and move on, right?
Edit: I find it hard to believe it relates to the null value, since the exception occurs during SessionFactory creation, before any objects are loaded from the database.
More updates: I downgraded to 5.6 and the error disappears. The project uses Ants currently, so it might be that optional foreign keys have been split off to a separate JAR file that was not added. I will try to create a minimal failing test case over the weekend.
Hibernate 6.0 is quite new and this might be a bug. Can you share which version you used exactly? Also, would it be possible for you to share the full mapping in the form of a reproducer so that we can fix this?
OK, I’ve got a set that crashes with a NullPointerException in buildMetadata() (at least that’s the line Java blames). Where do I submit the archive (I’d prefer a non-public location although I’ve done my best to scrub it of business data)?
Hey there. You can join us on Zulip and send me the project through a PM, but if it isn’t too much trouble for you, it would be best if you could attach it on a new JIRA issue with a small explanation about what is wrong.
The NPE seems to come in mapping.ToOne.sortProperties(), line 170, where getReferencedPropertyName() is null and entityBinding is also null (this causes the exception). I suspect it relates to the <composite-element>s in ProductionUnit#BlastFurnace (they used to have the same Java class, but making a new class did not resolve the issue). I suspect your JARs have all debug statements stripped, but is there a way to see where in the entity tree it is when the exception occurs without modifying and recompiling the source code?
Not sure what you mean by “without modifying and recompiling”, but you can configure logging through log4j or java.util.logging means. Anyway, thanks for the reproducer. I’ll try to look into it asap
Hey @zaleth81 , I am actually facing the exact same error and its troubling me since last 2 days, can you please tell me what did you do to solve the error in hibernate 6 when creating the sessionfactory?
Sorry, we’re still using older versions. Hopefully after next release they will let me get back to pushing Hibernate 6 (but first we should move from Struts to Spring …)