/* * Source code generated by Celerio, a Jaxio product. * Documentation: http://www.jaxio.com/documentation/celerio/ * Follow us on twitter: @jaxiosoft * Need commercial support ? Contact us: info@jaxio.com * Template pack-backend-jpa:src/main/java/configuration/JpaConfiguration.p.vm.java * Template is part of Open Source Project: https://github.com/jaxio/pack-backend-jpa */ package demo; import org.hibernate.SessionFactory; import org.hibernate.jpa.HibernateEntityManagerFactory; import org.springframework.beans.factory.annotation.Value; 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.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import javax.annotation.Resource; import javax.sql.DataSource; import java.util.Properties; @Configuration public class JpaConfiguration { @Resource(name = "dataSource") private DataSource dataSource; /** * Enable exception translation for beans annotated with @Repository */ @Bean public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { return new PersistenceExceptionTranslationPostProcessor(); } /** * @see http://www.springframework.org/docs/reference/transaction.html */ @Bean public JpaTransactionManager transactionManager() { return new JpaTransactionManager(); } /** * Build the entity manager with Hibernate as a provider. */ @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); emf.setDataSource(dataSource); // We set the persistenceXmlLocation to a different name to make it work on JBoss. emf.setPersistenceXmlLocation("classpath:META-INF/persistence.xml"); emf.setPersistenceUnitName("demoPU"); emf.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); return emf; } }