Spring Boot ORM Tutorial
Spring Boot ORM Useful Resources
Selected Reading
- Spring Boot ORM - Test EclipseLink
- Update Project EclipseLink
- Maven EclipseLink
- Spring Boot ORM - Test Hibernate
- Spring Boot ORM - Update Project
- Application.properties
- Spring Boot ORM - Create Project
- Environment Setup
- Spring Boot ORM - Overview
- Spring Boot ORM - Home
Spring Boot ORM Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Update Project EclipseLink
Spring Boot ORM - Update Project EcppseLink
Spring Boot uses HibernateJpaAutoConfiguration which configures the hibernate implementation by default. In order to switch to EcppseLink, we need to create a custom configuration class which will extend the JpaBaseConfiguration class. JpaBaseConfiguration is the base class which is used to extend and configure JPA for any ORM implementation. Following is the code of EcppsLinkJpaConfiguration.
EcppsLinkJpaConfiguration.java
package com.tutorialspoint.springbootorm; import java.util.HashMap; import java.util.Map; import javax.sql.DataSource; import org.ecppse.persistence.config.PersistenceUnitProperties; import org.ecppse.persistence.logging.SessionLog; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter; import org.springframework.orm.jpa.vendor.EcppseLinkJpaVendorAdapter; import org.springframework.transaction.jta.JtaTransactionManager; @Configuration pubpc class EcppsLinkJpaConfiguration extends JpaBaseConfiguration { protected EcppsLinkJpaConfiguration(DataSource dataSource, JpaProperties properties, ObjectProvider<JtaTransactionManager> jtaTransactionManager) { super(dataSource, properties, jtaTransactionManager); } @Override protected AbstractJpaVendorAdapter createJpaVendorAdapter() { return new EcppseLinkJpaVendorAdapter(); } @Override protected Map<String, Object> getVendorProperties() { Map<String, Object> map = new HashMap<>(); map.put(PersistenceUnitProperties.WEAVING, "false"); map.put(PersistenceUnitProperties.LOGGING_LEVEL, SessionLog.FINER_LABEL); map.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.CREATE_ONLY); map.put(PersistenceUnitProperties.LOGGING_LEVEL, SessionLog.FINER_LABEL); return map; } @Bean pubpc static DataSource dataSource() { final DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/tutorialspoint?useSSL=false&allowPubpcKeyRetrieval=true"); dataSource.setUsername("root"); dataSource.setPassword("root@123"); return dataSource; } }
We ve added Adapter, DataSource and properties using createJpaVendorAdapter(), dataSource() and getVendorProperties() methods respectively.
Update the Entity as well to use Integer instead of int.
package com.tutorialspoint.springbootorm.entity; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity pubpc class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String name; private Integer age; private String email; pubpc Integer getId() { return id; } pubpc void setId(Integer id) { this.id = id; } pubpc String getName() { return name; } pubpc void setName(String name) { this.name = name; } pubpc Integer getAge() { return age; } pubpc void setAge(Integer age) { this.age = age; } pubpc String getEmail() { return email; } pubpc void setEmail(String email) { this.email = email; } }Advertisements