How do I disable schema validation in Hibernate for certain entities (not all)? Some of my entities are using SQL which lead to fail validation so I want to disable validation for them.
Open the web service for which you wish to disable the XML Schema validation. Open the corresponding Operation Mapping. Click on the mapping properties->Advanced tab. Update the 'XML Schema Validation' property value to 'No Validation' (As stated below).
An API schema defines which API requests are valid based on several request properties like target endpoint and HTTP method. Schema Validation allows you to check if incoming traffic complies with a previously supplied API schema.
Hibernate Validator allows to express and validate application constraints. The default metadata source are annotations, with the ability to override and extend through the use of XML. It is not tied to a specific application tier or programming model and is available for both server and client application programming.
Quite an old question but I thought this might help.
Validation can be filtered by providing a custom org.hibernate.tool.schema.spi.SchemaFilterProvider
that specifies a org.hibernate.tool.schema.spi.SchemaFilter
to be used by validate operations. To use the custom provider (as @tomerz mentioned), the property hibernate.hbm2ddl.schema_filter_provider
must be set with the name of the class. For example, if using Hibernate as a JPA provider in the persistence.xml
add
<property name="hibernate.hbm2ddl.schema_filter_provider" value="com.my.package.MySchemaFilterProvider"/>.
It may be set programmatically as well (see Hibernate Programmatic Configuration)
The provider:
package com.my.package;
import org.hibernate.tool.schema.internal.DefaultSchemaFilter;
import org.hibernate.tool.schema.spi.SchemaFilter;
import org.hibernate.tool.schema.spi.SchemaFilterProvider;
public class MySchemaFilterProvider implements SchemaFilterProvider {
@Override
public SchemaFilter getCreateFilter() {
return DefaultSchemaFilter.INSTANCE;
}
@Override
public SchemaFilter getDropFilter() {
return DefaultSchemaFilter.INSTANCE;
}
@Override
public SchemaFilter getMigrateFilter() {
return DefaultSchemaFilter.INSTANCE;
}
@Override
public SchemaFilter getValidateFilter() {
return MySchemaFilter.INSTANCE;
}
}
The custom filter:
public class MySchemaFilter implements SchemaFilter {
public static final MySchemaFilter INSTANCE = new MySchemaFilter();
@Override
public boolean includeNamespace(Namespace namespace) {
return true;
}
@Override
public boolean includeTable(Table table) {
return !table.getName().contains("the name of the entity to exclude");
}
@Override
public boolean includeSequence(Sequence sequence) {
return true;
}
}
By doing that, the DefaultSchemaFilter
is used for all the operations on the database schema except the validation of the entities. The validation operations will be filtered by MySchemaFilter
.
I'm not sure which version of Hibernate you are using, but it can be done using the hibernate.hbm2ddl.schema_filter_provider
property.
From Hibernate Configuration:
Used to specify the org.hibernate.tool.schema.spi.SchemaFilterProvider to be used by create, drop, migrate, and validate operations on the database schema. SchemaFilterProvider provides filters that can be used to limit the scope of these operations to specific namespaces, tables and sequences. All objects are included by defau
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With