Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableTransactionManagement
- public class HibernateConfig {
- @Bean
- public LocalContainerEntityManagerFactoryBean entityManagerF() {
- LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
- em.setDataSource(dataSource());
- em.setPackagesToScan(new String[] {"com.gitreporter"});
- JpaVendorAdapter jpaAdapter = new HibernateJpaVendorAdapter();
- em.setJpaVendorAdapter(jpaAdapter);
- em.setJpaProperties(jpaProperties());
- return em;
- }
- @Bean
- public PlatformTransactionManager jpaTransactionManager(EntityManagerFactory emf) {
- JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
- jpaTransactionManager.setEntityManagerFactory(emf);
- return jpaTransactionManager;
- }
- private final Properties jpaProperties() {
- Properties properties = new Properties();
- properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
- return properties;
- }
- @Bean
- public DataSource dataSource() {
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
- dataSource.setUrl("jdbc:mysql://localhost:3306/MyDBNAME?useSSL=false");
- dataSource.setUsername("username");
- dataSource.setPassword("password");
- return dataSource;
- }
- @Bean
- public LocalContainerEntityManagerFactoryBean entityManagerF() {
- @Bean
- public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
- @NoRepositoryBean
- public interface GenericRepository<T, ID extends Serializable> extends JpaRepository<T, ID> {
- public List<T> findByAttributeContainsText(String attributeName, String text);
- }
- public class GenericRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID>
- implements GenericRepository<T, ID> {
- private EntityManager entityManager;
- public GenericRepositoryImpl(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
- super(entityInformation, entityManager);
- this.entityManager = entityManager;
- }
- }
- public interface RoleRepository extends GenericRepository<Role, Long> {
- }
Add Comment
Please, Sign In to add comment