Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package ua.biglib.salivon; import com.mysql.jdbc.Driver; import javax.sql.DataSource; import org.hibernate.dialect.DerbyTenSevenDialect; import org.springframework.context.annotation.Bean; import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; import org.springframework.jdbc.datasource.SimpleDriverDataSource; 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; /** * * @author salivon.i */ public class BookConfig { @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); emf.setDataSource(dataSource()); emf.setJpaVendorAdapter(jpaVendorAdapter()); return emf; } private JpaVendorAdapter jpaVendorAdapter() { HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter(); jpaVendorAdapter.setShowSql(true); jpaVendorAdapter.setGenerateDdl(true); jpaVendorAdapter.setDatabasePlatform(DerbyTenSevenDialect.class.getName()); return jpaVendorAdapter; } @Bean public DataSource dataSource() { SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); dataSource.setDriverClass(Driver.class); dataSource.setUrl("jdbc:mysql://localhost:3306/biglib"); dataSource.setUsername("root"); dataSource.setPassword(""); return dataSource; } // @Bean // public PlatformTransactionManager transactionManager() { // return new JpaTransactionManager(entityManagerFactory().getObject()); // } // // @Bean // public PersistenceExceptionTranslationPostProcessor exceptionTranslator() { // return new PersistenceExceptionTranslationPostProcessor(); // } }