aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authormrfoxygmfr <mrfoxygmfr@sch9.ru>2025-03-17 12:23:11 +0300
committermrfoxygmfr <mrfoxygmfr@sch9.ru>2025-03-17 12:23:11 +0300
commitef2bec524581a63d989fc3de70433a118bd905fa (patch)
treeabd166a5f65fd7c746bf216680bf8916bb4503a3 /src/main/java
parentfef1dc61af7373892eb32595ddc47329c2167d78 (diff)
feat(db): add hibernate session factory
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/config/HibernateConfig.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/config/HibernateConfig.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/config/HibernateConfig.java
new file mode 100644
index 0000000..7f7948a
--- /dev/null
+++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/config/HibernateConfig.java
@@ -0,0 +1,49 @@
+package ru.mrfoxygmfr.warehouse_accounting.db.config;
+
+import org.springframework.context.annotation.*;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
+import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
+
+import javax.sql.DataSource;
+import java.util.Properties;
+
+@Configuration
+@PropertySource("classpath:application.properties")
+public class HibernateConfig {
+ @Value("${database.driver}")
+ private String DB_DRIVER;
+ @Value("${database.url}")
+ private String DB_URL;
+ @Value("${database.username}")
+ private String DB_USERNAME;
+ @Value("${database.password}")
+ private String DB_PASSWORD;
+
+ @Bean(name = "entityManagerFactory")
+ public LocalSessionFactoryBean sessionFactory() {
+ LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
+ sessionFactory.setDataSource(oraDataSource());
+ sessionFactory.setPackagesToScan("ru.mrfoxygmfr.warehouse_accounting.db.models");
+
+ Properties hibernateProperties = new Properties();
+ hibernateProperties.setProperty("hibernate.hbm2ddl.auto", "update");
+ hibernateProperties.setProperty("connection_pool_size", "1");
+
+ sessionFactory.setHibernateProperties(hibernateProperties);
+
+ return sessionFactory;
+ }
+
+ @Bean
+ public DataSource oraDataSource() {
+ DriverManagerDataSource dataSource = new DriverManagerDataSource();
+
+ dataSource.setDriverClassName(DB_DRIVER);
+ dataSource.setUrl(DB_URL);
+ dataSource.setUsername(DB_USERNAME);
+ dataSource.setPassword(DB_PASSWORD);
+
+ return dataSource;
+ }
+} \ No newline at end of file