package no.valg.valgnatt.database;

import java.util.Properties;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;

@Configuration
public class DatabaseCommonHibernateSpringConfiguration {

    @Resource
    private DataSource dataSource;
    @Resource
    private Properties hibernateProperties;

    @Bean
    @DependsOn("flywayLoader")
    public LocalSessionFactoryBean sessionFactory() {
        LocalSessionFactoryBean factory = new LocalSessionFactoryBean();
        factory.setDataSource(dataSource);
        factory.setHibernateProperties(hibernateProperties);
        factory.setPackagesToScan("no.valg.valgnatt.database.hibernate");
        return factory;
    }

}
