Hibernate 5.5.5 JOINED继承跨Schema报错(HHH000099)求助
Hey there, let's break down why your InheritanceType.JOINED strategy is failing post-upgrade and how to fix it. The HHH000099 error (table not found) almost always points to a mapping or configuration mismatch between Hibernate 4.2 and 5.5.5—rarely a core bug, since 5.5.5 is a stable, widely-used release. Here are the most likely fixes:
1. Verify Schema and Table Annotations
Hibernate 5 tightened up schema handling compared to 4.2. If your ANIMAL table lives in the BASE schema, ensure you've explicitly defined this in your entity annotations:
- For the parent
Animalclass:@Entity @Table(name = "ANIMAL", schema = "BASE") // Explicit schema is critical here @Inheritance(strategy = InheritanceType.JOINED) public class Animal { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; // Other fields, getters, setters } - For the child
Catclass, confirm the primary key join column maps correctly to the parent table's ID:@Entity @Table(name = "CAT", schema = "BASE") @PrimaryKeyJoinColumn(name = "ANIMAL_ID") // Matches the foreign key in CAT table public class Cat extends Animal { // Cat-specific fields }
If you rely on a default schema in your database connection, double-check that Hibernate 5 is picking it up—add hibernate.default_schema=BASE to your Hibernate configuration (e.g., hibernate.cfg.xml or Spring properties) if needed.
2. Check Naming Strategy Changes
Hibernate 5 switched to a JPA-compliant default naming strategy (ImplicitNamingStrategyJpaCompliantImpl) which behaves differently from Hibernate 4.2's old strategy. If your entities don't explicitly specify table/column names, Hibernate might be generating unexpected names (e.g., lowercase instead of uppercase).
To force the old, explicit naming behavior, set the physical naming strategy in your config:
- For Spring Boot:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl - For plain Hibernate:
<property name="hibernate.physical_naming_strategy" value="org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl"/>
3. Validate HBM2DDL and Dialect Settings
- Ensure
hibernate.hbm2ddl.autois set appropriately (e.g.,updateorcreateif you're testing). If it's set tovalidate, Hibernate will strictly check that your entity mappings match the existing database schema—any mismatch (like missing schema in table references) will trigger the error. - Update your Hibernate dialect to match your database version. For example, if you're using MySQL 8, replace
MySQL5InnoDBDialectwithMySQL8Dialect—old dialects can cause unexpected table resolution issues.
4. Enable SQL Logging to Diagnose
Turn on Hibernate's SQL logging to see exactly what query is failing. Add these properties to your config:
hibernate.show_sql=true hibernate.format_sql=true hibernate.use_sql_comments=true
Look at the generated SQL for the ANIMAL table—if it's missing the BASE schema prefix, that confirms a schema mapping issue.
5. Rule Out Database Permissions
While less likely, confirm that your database user has read/write access to the BASE.ANIMAL table. Sometimes upgrade workflows accidentally change user permissions or schema ownership.
If you've gone through all these steps and still see the error, share your full entity mappings and Hibernate configuration, and we can dig deeper—but odds are one of these fixes will resolve the HHH000099 error.
内容的提问来源于stack exchange,提问作者Vincent

