Sejak Hibernate 5.2.18, Anda dapat menggunakan utilitas MetadataBuilderContributor untuk menyesuaikan MetadataBuilder bahkan jika Anda melakukan bootstrap melalui JPA.
MetadataBuilderContributor
antarmuka dapat diimplementasikan seperti ini:
public class SqlFunctionsMetadataBuilderContributor
implements MetadataBuilderContributor {
@Override
public void contribute(MetadataBuilder metadataBuilder) {
metadataBuilder.applySqlFunction(
"group_concat",
new StandardSQLFunction(
"group_concat",
StandardBasicTypes.STRING
)
);
}
}
Dan, kami dapat menyediakan SqlFunctionsMetadataBuilderContributor melalui properti konfigurasi hibernate.metadata_builder_contributor:
<property>
name="hibernate.metadata_builder_contributor"
value="com.vladmihalcea.book.hpjp.hibernate.query.function.SqlFunctionsMetadataBuilderContributor"
</property>
Referensi:https://vladmihalcea.com/hibernate-sql- function-jpql-criteria-api-query/