diff --git a/backend/src/main/java/com/magistr/app/config/tenant/TenantDataSourceConfig.java b/backend/src/main/java/com/magistr/app/config/tenant/TenantDataSourceConfig.java index 171493d..c7674b6 100644 --- a/backend/src/main/java/com/magistr/app/config/tenant/TenantDataSourceConfig.java +++ b/backend/src/main/java/com/magistr/app/config/tenant/TenantDataSourceConfig.java @@ -5,12 +5,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -44,7 +44,7 @@ public class TenantDataSourceConfig implements WebMvcConfigurer { @Bean @Primary - public TenantRoutingDataSource tenantRoutingDataSource() { + public DataSource dataSource() { TenantRoutingDataSource routingDataSource = new TenantRoutingDataSource(); // Загружаем тенантов из JSON @@ -78,26 +78,28 @@ public class TenantDataSourceConfig implements WebMvcConfigurer { } @Bean - @Primary - public DataSource dataSource(TenantRoutingDataSource tenantRoutingDataSource) { - return tenantRoutingDataSource; + public TenantRoutingDataSource tenantRoutingDataSource(DataSource dataSource) { + return (TenantRoutingDataSource) dataSource; } @Bean @Primary - public LocalContainerEntityManagerFactoryBean entityManagerFactory( - DataSource dataSource, EntityManagerFactoryBuilder builder) { + public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { + LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(dataSource); + em.setPackagesToScan("com.magistr.app.model"); - Map jpaProps = new HashMap<>(); - jpaProps.put("hibernate.hbm2ddl.auto", "update"); - jpaProps.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect"); + HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + vendorAdapter.setGenerateDdl(true); + vendorAdapter.setDatabasePlatform("org.hibernate.dialect.PostgreSQLDialect"); + em.setJpaVendorAdapter(vendorAdapter); - return builder - .dataSource(dataSource) - .packages("com.magistr.app.model") - .persistenceUnit("default") - .properties(jpaProps) - .build(); + Map props = new HashMap<>(); + props.put("hibernate.hbm2ddl.auto", "update"); + props.put("hibernate.show_sql", "false"); + em.setJpaPropertyMap(props); + + return em; } @Bean