Step 1:
In your application.properties
spring.jpa.properties.hibernate.hbm2ddl.schema_filter_provider=<your class with pacakge>
spring.jpa.properties.hibernate.hbm2ddl.schema_filter_provider=com.drvijay.ExcludeFilter
or application.yml
spring:
jpa:
properties:
hibernate:
hbm2ddl:
schema_filter_provider: com.drvijay.ExcludeFilter
Step 2: ExcludeFilter.java
package com.drvijay;
import java.util.Arrays;
import java.util.List;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.Sequence;
import org.hibernate.mapping.Table;
import org.hibernate.tool.schema.spi.SchemaFilter;
import org.hibernate.tool.schema.spi.SchemaFilterProvider;
public class ExcludeFilter implements SchemaFilterProvider
{
@Override
public SchemaFilter getCreateFilter ()
{
return MySchemaFilter.INSTANCE;
}
@Override
public SchemaFilter getDropFilter ()
{
return MySchemaFilter.INSTANCE;
}
@Override
public SchemaFilter getMigrateFilter ()
{
return MySchemaFilter.INSTANCE;
}
@Override
public SchemaFilter getValidateFilter ()
{
return MySchemaFilter.INSTANCE;
}
}
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 )
{
List <String> list = Arrays.asList ( "table1", "table2" );
if ( list.contains ( table.getName ().toLowerCase () ) )
{
return false;
}
return true;
}
@Override
public boolean includeSequence ( Sequence sequence )
{
return true;
}
}
No comments:
Post a Comment