Answer the question
In order to leave comments, you need to log in
What components and data are needed for the HibernateTransactionManager to function?
For the normal operation of the Manager, you have to set the 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;
}
<?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>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question