Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Spring Data JPA @EnableJpaRepositories configuration in detail     - MySQL optimization resulting order by using filesort (Database)

- C ++ pointer of the (error-prone model) (Programming)

- Redis 3.0.3 Cluster Setup (Database)

- Mac OS X 10.10 Yosemite compiling OpenJDK 9 (Linux)

- Linux Command Study Notes (Linux)

- How to remove the files inside the privacy of data on Linux (Linux)

- Gnu Linux - Ubuntu System Clean-term consolidation (Linux)

- Ubuntu and derivatives installation Atom 0.104.0 (Linux)

- Install and configure GO 1.2.1 under CentOS 6.5 (Linux)

- How to release the cache memory on Linux (Linux)

- FreeRadius installation process record (Linux)

- Node.js installed on Ubuntu Upstream version (Linux)

- Android using SVG vector graphics to create cool animation effects (Programming)

- The Linux role of each directory contents (Linux)

- Whisker Menu 1.4.3 Install menu Linux (Linux)

- Visual Studio Code experience (Linux)

- Using Oracle for Oracle GoldenGate to achieve a one-way data synchronization (Database)

- To use Linux to create a secure managed gateway (Linux)

- sed and awk in shell usage and some examples (Linux)

- CentOS 6.5 / Linux restart network card being given Determining if ip address x.x.x.x is already in use (Linux)

 
         
  Spring Data JPA @EnableJpaRepositories configuration in detail
     
  Add Date : 2018-11-21      
         
         
         
  @EnableJpaRepositories Srping JPA annotations for configuration code, the form used to replace the xml configuration files, configurations @ EnableJpaRepositories supports rich multi-purpose, this article explain in detail.

1, simple configuration

@EnableJpaRepositories ( "Com.spr.repository")
Simple configuration supports multiple package, in the following format:

@EnableJpaRepositories ({ "Com.cshtong.sample.repository", "com.cshtong.tower.repository"})
2, single-valued and multi-group configuration values

Most annotations can support a plurality of individual notes and annotations manner, a plurality of notes usually "{}" contains a group of data symbols.

For example: a string of "x.y.z" => { "x.y.z", "a.b.c"}

Category: A.class => {A.class, B.class}

3, complete @EnableJpaRepositories comment

 1 @EnableJpaRepositories (
 2 basePackages = {},
 3 basePackageClasses = {},
 4 includeFilters = {},
 5 excludeFilters = {},
 6 repositoryImplementationPostfix = "Impl",
 7 namedQueriesLocation = "", // META-INF / jpa-named-queries.properties
 8 queryLookupStrategy = QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND, //QueryLookupStrategy.Key.x
 9 repositoryFactoryBeanClass = JpaRepositoryFactoryBean.class, // class
10 entityManagerFactoryRef = "entityManagerFactory",
11 transactionManagerRef = "transactionManager",
12 considerNestedRepositories = false,
13 enableDefaultTransactions = true
14)
Following is a breakdown of the role of each configuration item

1) basePackage

Used to configure the scanning Repositories where the package and the child package. Simple configuration This configuration is equivalent to the configuration values, basePackages can be configured as a single string, it can also be configured as a string array.

1 @EnableJpaRepositories (
2 basePackages = "com.cshtong")
A plurality of package path

1 @EnableJpaRepositories (
2 basePackages = { "com.cshtong.sample.repository", "com.cshtong.tower.repository"})
 

2) basePackageClasses

Specifies Repository class

1 @EnableJpaRepositories (basePackageClasses = BookRepository.class)
1 @EnableJpaRepositories (
2 basePackageClasses = {ShopRepository.class, OrganizationRepository.class})
Note: When the test found a configuration package Repositories class class within that package will be loaded other Repositores

3) includeFilters

Filter, the filter area using ComponentScan filter class

1 @EnableJpaRepositories (
2 includeFilters = {@ ComponentScan.Filter (type = FilterType.ANNOTATION, value = Repository.class)})
 

4) excludeFilters

It does not contain a filter

1 @EnableJpaRepositories (
2 excludeFilters = {
3 @ ComponentScan.Filter (type = FilterType.ANNOTATION, value = Service.class),
4 @ ComponentScan.Filter (type = FilterType.ANNOTATION, value = Controller.class)})
 

5) repositoryImplementationPostfix

Tail achieve additional classes, such as ShopRepository, corresponding to ShopRepositoryImpl

6) namedQueriesLocation

named SQL storage location, the default is META-INF / jpa-named-queries.properties

7) queryLookupStrategy

Construction Strategy query terms, including three ways to CREATE, USE_DECLARED_QUERY, CREATE_IF_NOT_FOUND

CREATE: automatically build a query in accordance with the interface name
USE_DECLARED_QUERY: user query statement
CREATE_IF_NOT_FOUND: First search for a user-defined, automated build does not exist
The policy is automatically generated by a query against the interface name follows the scene

  List < Person> findByEmailAddressAndLastname (EmailAddress emailAddress, String lastname);

  // Enables the distinct flag for the query
  List < Person> findDistinctPeopleByLastnameOrFirstname (String lastname, String firstname);
  List < Person> findPeopleDistinctByLastnameOrFirstname (String lastname, String firstname);

  // Enabling ignoring case for an individual property
  List < Person> findByLastnameIgnoreCase (String lastname);
  // Enabling ignoring case for all suitable properties
  List < Person> findByLastnameAndFirstnameAllIgnoreCase (String lastname, String firstname);

  // Enabling static ORDER BY for a query
  List < Person> findByLastnameOrderByFirstnameAsc (String lastname);
  List < Person> findByLastnameOrderByFirstnameDesc (String lastname)
8) repositoryFactoryBeanClass

Repository specified factory class

9) entityManagerFactoryRef

Entity manager factory reference name corresponding to the annotation of the method @Bean

 1 @Bean
 2 public LocalContainerEntityManagerFactoryBean entityManagerFactory () {
 3 LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean ();
 4 entityManagerFactoryBean.setDataSource (dataSource ());
 5 entityManagerFactoryBean.setPersistenceProviderClass (HibernatePersistenceProvider.class);
 6 entityManagerFactoryBean
 7 .setPackagesToScan (env.getRequiredProperty (PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
 8 entityManagerFactoryBean.setJpaProperties (hibProperties ());
 9 return entityManagerFactoryBean;
10}
10) transactionManagerRef

Organiser factory reference name corresponding to the annotation of the method @Bean

@Bean
public JpaTransactionManager transactionManager () {
    JpaTransactionManager transactionManager = new JpaTransactionManager ();
    transactionManager.setEntityManagerFactory (entityManagerFactory () getObject ().);
    return transactionManager;
}
     
         
         
         
  More:      
 
- What factors affect the performance of Java calls (Programming)
- Linux smart small switch rfkill (Linux)
- Achieve single backup of MySQL by innobackupex (Database)
- Use cmake to compile and install MySQL 5.5 (Database)
- Ubuntu firewall installation and configuration (Linux)
- Three strategies to teach you to release the device memory (Linux)
- Using the Linux VNC service (Server)
- Using LLVM Clang and Blocks under Linux (Programming)
- Log in CentOS 6.5 Multi-user setting VNC (Server)
- 5 interesting Linux command line tips (Linux)
- Introduction Linux namespace (Linux)
- Linux uses shared memory communication process synchronization Withdrawal (Programming)
- 15 things to do after installing Ubuntu 15.04 Desktop (Linux)
- Linux Network Programming - raw socket instance: MAC header message analysis (Programming)
- CentOS 6.6 compile and install phpMyAdmin configuration PostgreSQL9.4.1 (Database)
- How to use OpenVPN and PrivacyIDEA build two-factor authentication for remote access (Server)
- Recovery from MySQL master data consistency summary (Database)
- TypeScript basic grammar (Programming)
- Error: Unable to establish connection with FTP SFTP server (Server)
- Use backup-manager system backup on Linux (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.