diff --git a/integration/hibernate-base/src/main/java/com/blazebit/persistence/impl/hibernate/HibernateJpaProvider.java b/integration/hibernate-base/src/main/java/com/blazebit/persistence/impl/hibernate/HibernateJpaProvider.java index 350a0c9096..30dc25ce2e 100644 --- a/integration/hibernate-base/src/main/java/com/blazebit/persistence/impl/hibernate/HibernateJpaProvider.java +++ b/integration/hibernate-base/src/main/java/com/blazebit/persistence/impl/hibernate/HibernateJpaProvider.java @@ -502,12 +502,19 @@ public String[] getColumnTypes(EntityType entityType, String attributeName) { } // In this case, the property might represent a formula - if (columnNames.length == 1 && columnNames[0] == null) { + boolean isFormula = columnNames.length == 1 && columnNames[0] == null; + boolean isSubselect = tables.length == 1 && tables[0] == null; + + if (isFormula || isSubselect) { Type propertyType = entityPersister.getPropertyType(attributeName); long length; int precision; int scale; try { + if (propertyType instanceof org.hibernate.type.EntityType) { + propertyType = ((org.hibernate.type.EntityType) propertyType).getIdentifierOrUniqueKeyType(sfi); + } + Method m = Type.class.getMethod("dictatedSizes", Mapping.class); Object size = ((Object[]) m.invoke(propertyType, sfi))[0]; length = (long) size.getClass().getMethod("getLength").invoke(size);