41 lines
1.4 KiB
Java
41 lines
1.4 KiB
Java
package eu.dnetlib.repo.manager.config;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
|
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
|
import org.springframework.orm.jpa.JpaVendorAdapter;
|
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
|
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
|
import org.springframework.transaction.PlatformTransactionManager;
|
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
|
|
import javax.persistence.EntityManagerFactory;
|
|
import javax.sql.DataSource;
|
|
|
|
@Configuration
|
|
@EnableTransactionManagement
|
|
public class JpaConfig {
|
|
|
|
@Autowired
|
|
DataSource dataSource;
|
|
|
|
@Autowired
|
|
EntityManagerFactory entityManagerFactory;
|
|
|
|
@Bean
|
|
public PlatformTransactionManager transactionManager() {
|
|
JpaTransactionManager transactionManager = new JpaTransactionManager();
|
|
transactionManager.setEntityManagerFactory(entityManagerFactory);
|
|
|
|
return transactionManager;
|
|
}
|
|
|
|
@Bean
|
|
public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
|
|
return new PersistenceExceptionTranslationPostProcessor();
|
|
}
|
|
|
|
}
|