'Multitenant Hibernate schema creation

I'm creating a multi-tenacy application with Spring Boot Jpa and Hibernate.

Before adding the multi-tenacy feature, the schema was generated automatically by JPA but now I'm doing manually and all the annotations of javax.validations are not processed and all the columns with @NotNull are ignored and are nullables.

Map<String, String> settings = new HashMap<>();
settings.put(AvailableSettings.URL, ""); // jdbc:postgresql...
settings.put(AvailableSettings.USER, ""); // username
settings.put(AvailableSettings.PASS, ""); // password
settings.put(AvailableSettings.DIALECT, "org.hibernate.spatial.dialect.postgis.PostgisDialect");
settings.put(AvailableSettings.PHYSICAL_NAMING_STRATEGY, CamelCaseToUnderscoresNamingStrategy.class.getName());
settings.put(AvailableSettings.SHOW_SQL, "true");

StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(settings).build();

MetadataSources metadataSources = new MetadataSources(serviceRegistry);
setEntities.forEach(metadataSources::addAnnotatedClass); // Add all entities

metadata = metadataSources.buildMetadata();

SchemaUpdate update = new SchemaUpdate().setHaltOnError(true);
update.execute(EnumSet.of(TargetType.DATABASE), metadata);

Is there any way to add this annotation processing?

The only way I have found is with @Column(nullable = false)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source