Posting this here because I can’t log in to the issue tracker: Cannot log in to report issue and because I’m not sure if this is a user error or a bug.
When using TABLE_PER_CLASS inheritance, hibernate 6.6.22, and postgres 17 (postgres 15 dialect based on the versions though), we get an NPE when hibernate tries to build the union subclass query. Debugging this shows that hibernate is determining the jdbc type as other and failing to build the cast query.
Given entities like
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Parent {
@Id
@Column(name = "id")
@AssignedOrDefaultIdentity
private UUID id;
}
@Entity
@Table(name = "child_1")
public class Child1 extends Parent {
@Column(name = "additions", columnDefinition = "jsonb")
@Type(JsonUserType.class)
@JdbcTypeCode(SqlTypes.JSON)
private Map<String, Object> additions = Collections.emptyMap();
}
@Entity
@Table(name = "child_2")
public class Child2 extends Parent {
}
We get a NPE on this method
@Override
public String getSelectClauseNullString(int sqlType, TypeConfiguration typeConfiguration) {
// TODO: adapt this to handle named enum types!
// Workaround for postgres bug #1453
return "cast(null as " + typeConfiguration.getDdlTypeRegistry().getDescriptor( sqlType ).getRawTypeName() + ")";
}
because the DdlTypeRegistry doesn’t have the ddl for the additions column (1111 = OTHER) when building the data for the child2 table. It appears to run into this for loop correctly
for ( Column col : columns ) {
if ( !table.containsColumn( col ) ) {
int sqlType = col.getSqlTypeCode( mapping );
subquery.append( dialect.getSelectClauseNullString( sqlType, getFactory().getTypeConfiguration() ) )
.append(" as ");
}
Not sure what the best fix for this is. I think hibernate should be using the ddl type mapping of the original subclass when building the “virtual” column on the 2nd subclass.