JAVA entry [21]-simple Spring Data JPA example,-springjpa
Spring has powerful support for JPA. Developers only need to focus on the implementation code of core business logic, and do not need to focus too much on the creation of E
Preface:
Based on the Spring Framework 4.x or Spring Boot 1.x development environment
It is important to note the following version issues:Spring framework4.x (Spring boot1.x) corresponds to spring-data1.x
Spring framework5.x (Spring
ObjectiveFrom the title of the article, it can be clearly understood that this article is to discriminate between three easy to confuse the novice technical terminology. If you know the difference and the relationship between the three nouns at the glance of the past, then this article you can not continue to read, unless you want to see what I have to explain the wrong, to correct (to find fault, haha), also welcome messages.noun explanation
JPA
ObjectiveFrom the title of the article, it can be clearly understood that this article is to discriminate between three easy to confuse the novice technical terminology. If you know the difference and the relationship between the three nouns at the glance of the past, then this article you can not continue to read, unless you want to see what I have to explain the wrong, to correct (to find fault, haha), also welcome messages.noun explanation
JPA
Scene:Now, one of the things that is provided in the service is to remove all eligible data before inserting all new conditions into the databaseThis scenario requires a two-step implementation of the service1. Delete2. InsertThese two steps are naturally done in the same transaction, which is a complete operation.So for this scenario, let's see how the annotations work.1 "First look at the DAO layer link: http://www.cnblogs.com/sxdcgaq8080/p/8984140.
The Jpa:java persistence API is a Java persistence specification. It provides Java developers with an object/mapping tool to manage relational data in Java applications. The goal is to simplify persistent development efforts and integrate ORM technology.Spring Data JPA is a set of JPA application frameworks encapsulate
TopLink.
Used in the project as: in the entity class, use @Entity , @Table , @Id and @Column other annotations.
The sample code is as follows:
import javax.persistence.*;import javax.persistence.Id;@Entity@Table(name = "t_user")//数据库中表名public class UserEO { @Id @Column(name = "USER_ID")//数据库中字段名 private String userId; @Column(name = "USER_NAME") private String userName; }
The jar package structure looks like this:
What is 2.
What is spring data? Spring data is an open source framework for simplifying database access and supporting cloud services. Its primary goal is to make access to data easy and efficient, and to support map-reduce frameworks and cloud computing
Org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate ( Runaftertestmethodcallbacks.java:86) at Org.springframework.test.context.junit4.statements.SpringRepeat.evaluate (SpringrepeatInitially thought to be its own configuration problem, after the check found no errorMay be a jar package conflict after analysisUpgrade the Spring-orm jar package to a higher version problem resolutionSpring Boot configuration
In the process of using spring data JPA, the use of Ehcache to do caching, whether the need for level two cache, generally do not need to see the business needs, because this thing if the configuration is not good, but will lead to performance degradation, but if it is some data, basically do not change, long-term unch
feature repository typically queries the underlying data store. Springdata these queries into a four-step process:1. Declare an interface extension library and type it, or one of its child domain classes and ID types, it will handle.Interface Personrepository extends Repository2, the method of new conditional query on the interface.Interface Personrepository extends RepositoryList}3. To create proxy instances for these interfaces, you can pass Javaco
feature exists. Test declares that it has an open, committed, closed feature, but does not have a rollback feature, and the transation in test is the most important to decide whether or not to commit to the database, which plays a role in protecting the data site.2. When integrating spring MVC, classes with @service are not scanned in the MVC configuration file, which causes transactions to become normal b
Maven Project Build spring boot + spring mvc + JPA example, mavenmvc
This article describes how to build spring boot + spring mvc + JPA by using Maven:
Add
servlet/jsp of the Web The most revolutionary thing to use in the application,Hibernate can be applied in the EJB of the Java the schema replaces CMP to complete the task of data persistence. OrmORM is the meaning of the object-relational mapping, English: Object Relational Mapping abbreviation ORM is a program technology that enables data conversion between systems of different system types in an object-o
by spring data JPA * @NoRepositoryBean public in Terface genericrepository
Custom extension Implementation class: Genericrepositoryimpl, where the other methods are global shared methods, that is, each user interface that inherits the custom extension interface can use these functions
Package Com.wonders.frame.core.dao.impl;
Import java.io.Serializable;
Import
be provided here in the form of attribute injection.
Second, Spring implements some of the features that are part of the EJB container environment, such as container injection support for @PersistenceContext, @PersistenceUnit.
Third, and the most significant, Spring will entitymanager creation and destruction, transaction management and other code extraction, and by its unified management, develope
SQL statements?For example: The two classes of our userrepository and Userrepositoryimpl are written as follows.Public interface Userrepository extends JparepositorySo why do you do this here? The reason: SPRING-DATA-JPA provides the underlying crud work, but also provides the functionality of the business logic (whic
are used to explain the way. This book is divided into 3 parts, a total of 12 chapters.(1) Basic part: The whole understanding of JPA, JPA Basic Query method, definition Query method, annotated query method, @Entity Examples of common annotations in detail, understand the basic use and syntax of Spring Data
Recently work too busy, so delayed to everyone to share the actual combat springboot framework use.The following is the use of spring boot to integrate multiple frameworks.The first is to prepare for the job well.The first import framework requires packages that we use for MAVEN to manage the package.The above example is my h5ds real background management project, this project is in the hospitality financin
Learn article from: Http://www.ityouknow.com/spring-boot.htmlspring data JPA Introduction First understand what JPA is?JPA (Java Persistence API) is the Java Persistence specification proposed by Sun. It provides Java developers with an object/association mapping tool to man
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.