SPRING-DATA-JPA detailed, all-round introduction.

Source: Internet
Author: User

This article is an introduction to SPRING-DATA-JPA that covers almost all aspects of the framework, and in the daily development, it basically satisfies all requirements. JPA and SPRING-DATA-JPA are not explained here alone, and all of the content is implemented in an environment that is integrated with spring. If you need to understand the framework of getting started, Baidu a bit, a lot of introductory introduction. In the next article in this article, there will be a series to explain MyBatis, the series from the beginning of MyBatis, to basic use, and spring integration, and third-party plug-ins integration, caching, plug-ins, and finally will continue to MyBatis architecture, source interpretation, The focus will introduce several important design patterns, such a system. After basically speaking, mybatis in front of you there is no secret, you can solve mybatis almost all problems, and in the development process is quite convenient, comfortable. This article because of the introduction of the class is very full, so very long, if you need, then you can read patiently, I experienced a long time of learning, use, research efforts to condense into such a short blog. Roughly organize an outline: 1, the basic introduction of SPRING-DATA-JPA, 2, and Spring integration, 3, the basic way of use; 4, complex query, including multi-table association, paging, sorting, etc. start now: 1, SPRING-DATA-JPA Basic Introduction: The reason for JPA is to integrate the third-party ORM framework, the establishment of a standard way, Baidu Encyclopedia is the JDK in order to achieve the world of ORM, is now in accordance with this direction, but has not been fully realized. In the ORM Framework, hibernate is a very large force, widely used, also very convenient, the ability is very strong, and Hibernate is also a good integration with JPA, we can think of JPA is the standard, in fact, JPA is almost the interface,  The implementation is hibernate in doing, macro above look, under JPA unification hibernate very well run. The relationship between JPA and Hibernate is described above, so what is SPRING-DATA-JPA? This place needs a little explanation, we do Java development know spring is strong, so far, enterprise application Spring is almost omnipotent, ubiquitous, is already the de facto standard, enterprise application does not use spring's almost no, so that's right. and spring's ability to integrate third-party frameworks is strong, and he's not just going to do the first IOC container as simple as this, but now spring is too broad, mainly in the integration with third-party tools. And in the context of integration with third parties, Spring has done this work of persistence, and my personal feeling is SprinG Want to take the persistence of this piece of content also to win. So there is spring-data-** this series of packages. Including, Spring-data-jpa,spring-data-template,spring-data-mongodb,spring-data-redis, and a folk product, mybatis-spring, like the front,  This is a third-party package integrated with MyBatis, which is a dry persistence tool.  This is the introduction of SPRING-DATA-JPA, which represents integration with JPA. 2, we all know that when using the persistence tool, there is generally an object to operate the database, in the native hibernate called the session, in the JPA called Entitymanager, in MyBatis called Sqlsession, Use this object to manipulate the database. We generally according to the three-layer structure, the service layer to do business logic processing, DAO layer and database dealings, in the DAO, there is the above object. So what are the features that the ORM framework itself provides? The answer is basic crud, all of the underlying CRUD frameworks are provided, we use it to feel very convenient, very strong, the business logic level of processing ORM is not provided, if the use of the native framework, business logic code we will generally customize, we will write the SQL statement, and then execute. At this time, the power of SPRING-DATA-JPA is manifested, ORM provides the capabilities he has to offer, ORM Framework does not provide the business logic function SPRING-DATA-JPA also provides, all-round solution to the needs of users. In the process of developing with SPRING-DATA-JPA, we hardly need to write an SQL statement, at least in my opinion, enterprise applications can basically not write any SQL, of course, SPRING-DATA-JPA also provide their own way of writing SQL, This depends on how the individual chooses, all can.  I think it's all right. 2.1 Integration with spring we start with the spring configuration file, in order to save space, here I only write the configuration file structure.    Copy Code Copy Code 2.2 to the above configuration file for a simple explanation, only the "Entity manager" and "DAO" interpretation, the other configuration anywhere is not too much. 1. Explanation of the "entity manager": We know that the configuration information of the native JPA must be placed under the Meta-inf directory, And the name must be called Persistence.xml, this is called Persistence-unit, is called the persistence unit, placed under this we feel inconvenient, not good, so spring provides the org.springframework.orm.Jpa. Localcontainerentitymanagerfactorybean such a class, you can make the arbitrary configuration of the name of the file, you can change the location of the file as you like, just point to this location on the line. However, it is more convenient to write the configuration information directly here, so that the entity manager is the Bean. Use

SPRING-DATA-JPA detailed, comprehensive introduction.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.