Для нормальной работы Manager-а приходится set-ать DataSource
public class DataBaseConfig {
private static final String url="jdbc:mysql://localhost:3306/BASE?useLegacyDatetimeCode=false&serverTimezone=UTC";
private static final String driverClassName="com.mysql.cj.jdbc.Driver";
private static final String userName="root";
private static final String password="1234";
@Bean
public DataSource dataSource() {
BasicDataSource ds=new BasicDataSource();
ds.setUrl(url);
ds.setDriverClassName(driverClassName);
ds.setUsername(userName);
ds.setPassword(password);
return ds;
}
}
@Bean
public SessionFactory sessionFactory() throws IOException {
LocalSessionFactoryBean sessionFactoryBean=new LocalSessionFactoryBean();
sessionFactoryBean.setConfigLocation(new ClassPathResource("hibernate.cfg.xml"));
sessionFactoryBean.setPackagesToScan("ru.cource.model.domain");
sessionFactoryBean.afterPropertiesSet();
return sessionFactoryBean.getObject();
}
@Bean
public PlatformTransactionManager transactionManager() throws IOException {
HibernateTransactionManager transactionManager = new HibernateTransactionManager();
transactionManager.setDataSource(dataSource());
transactionManager.setSessionFactory(sessionFactory());
return transactionManager;
}
При удалении DataSource получаю UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource] .
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url" >jdbc:mysql://localhost:3306/BASE?useLegacyDatetimeCode=false&serverTimezone=UTC</property>
<property name="connection.driver_class" >com.mysql.cj.jdbc.Driver</property>
<property name="connection.username">root</property>
<property name="connection.password">1234</property>
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">validate</property >
<property name="hibernate.dialect" >org.hibernate.dialect.MySQL8Dialect</property >
</session-factory>
</hibernate-configuration>
Можно ли обойтись без создания дублирующего property файла для конфигурации DataSource?