34-Spring Boot - Spring Data Flashcards
What is the starter for Spring JPA?
spring-boot-starter-data-jpa
What jars are inside Spring JPA?
- spring-boot-starter.jar
- spring-boot-starter-jdbc.jar
- spring-boot-starter-aop.jar
- spring-data-jpa.jar
- hibernate-core.jar
- javax.transaction-api
What happens if Spring boot found JPA on the classpath?
It will auto-configure:
- DataSource
- LocalContainerEntityManagerFactoryBean
- JpaTransactionManager
How to customize EntityManager?
Configure the bean LocalContainerEntityManagerFactoryBean and set:
- JpaVendorAdapter e.g. HibernateJpaVendorAdapter
- JpaProperties e.g. hibernate.format_sql
- Datasource
- PackagesToScan
What is the purpose of @EnableAutoConfiguration? Does it belong to spring framework or spring boot?
- Enable auto-configuration of the Spring Application Context, attempting to guess and configure beans that you are likely to need.
Auto-configuration classes are usually applied based on your classpath and what beans you have defined - Part of Spring Boot
What beans will be scanned with @EnableAutoConfiguration?
- Package of the config class annotated with @EnableAutoConfiguration
- All sub-packages
In Spring Boot, how to customize the packages that will be scanned for entities?
Using @EntityScan e.g.
@SpringBootApplication
@EntityScan(“my.package”)
public class Application {}
Spring JPA: how to customize DB name?
spring.jpa.database=my-db-name
Spring JPA: how to disable the feature that creates tables automatically?
spring.jpa.hibernate.ddl-auto=none
What are options for spring.jpa.hibernate.ddl-auto? What is the default one?
none validate update create create-drop (default)
How to show SQL queries in a nice format?
spring. jpa.show-sql=true
spring. jpa.properties.hibernate.format_sql=true
How to set a custom property for Hibernate?
spring.jpa.properties.hibernate.xxx=…
What ORMs does Spring support?
Hibernate only
What are the benefits of using Spring data?
- Reduce boilerplate code for data access
2. Works in many environments
List out 6 sub-projects of Spring Data
- JPA
- MongoDB
- Redis
- Neo4j
- Hadoop
- Solr