A preliminary understanding of JPA, a preliminary understanding of English
I thought about what job I was about to do when I left school in the graduation season in and. In order to have a good salary, you can develop for a long time, which is exactly what you like. Therefore, they decided to join the computer industry. That was the hot time of JAVA. JAVA training and enrollment are everywhere. At that time, the learning model basically learned basic courses such as java se, web, and database, and began to learn the so-called java ee content. A large part of the content is the SSH framework, Struts + Spring + Hibernate.
When getting started with the project, the Hibernate framework is generally used to connect to the database, although iBatis was also known at that time (it was also during the conversion from iBatis to myBatis ). Most of the databases used at that time use MySQL, and Oracle is also used in many cases. A large number of clients on the market use Windows Server, which uses SQL Server. So I was wondering if I could use Hibernate to encapsulate it into my own module. It can be easily transferred between these common databases.
In fact, at that time, Hibernate did not learn too deeply. It is only a small level of API use. Let alone focus on the performance of the ORM framework, let alone compare several ORM frameworks and select the appropriate project architecture.
After a few years, I left JAVA to do ActionScript 3, so I no longer learned JAVA. At that time, if I continued to work in JAVA, I had been learning JAVA, and I learned other ORM frameworks than Hibernate. I believe that I will also want to encapsulate a module to operate the database. The framework is Hibernate, myBatis, or other ORM framework. We hope this module can also be easily embedded into Hibernate, myBatis, or something else. The application only needs to use this module to operate the database. If the performance of the later ORM framework is improved, you can immediately copy the jar package of the framework to the application. This module naturally becomes based on this ORM framework.
No, good news. JAVA officially did this. That is, we are all concerned about JPA, JPA, and JPA (the important thing is said three times ).
So what is JPA? From my previous descriptions, I believe we can guess what JPA is.
Let's take a look at how experts describe it.
Let's take a look at the official Oracle Java Persistence API, which is shown on the page:
The Java Persistence API provides a POJO persistence model for object-relational mapping. The Java Persistence API was developed by the EJB 3.0 software expert group as part of JSR 220, but its use is not limited to EJB software components. It can also be used directly by web applications and application clients, and even outside the Java EE platform, for example, in Java SE applications. See JSR 220.
I translated this into Chinese:
JPA (Java Persistence API) provides an object Persistence model solution for "Object-relationship" ing (this requirement), which was developed by EJB3.0 software expert group as part of JSR220. However, the use of JPA is not limited to EJB components. It (JPA) can be directly used by Web applications and client applications. It is even used outside the Java EE platform, for example, in Java SE. For details, see JSR 220.
Oh, I don't think it's easy to understand. Let's take a look at Baidu encyclopedia, which is like this:
JPA stands for Java Persistence API. JPA describes the ing relationship between object-relational tables through JDK 5.0 annotations or XML, and persists object objects in the database at runtime.
In fact, two functions are described here. One is how to mark how the data in object-1 relational database corresponds. here we can use the JDK5.0 annotation or XML configuration file. Another feature is that all objects have been mapped to the data in the relational database. Naturally, it is how to store these objects. In professional terms, objects are persistently stored in the database.
Of course, the complete functions of JPA are generally described on the Internet at three points. In addition to the two points, the other point is how to query data from the object perspective. They are very professional, but they have invented a language called Query Language JPQL. For descriptions of these three functions, refer to the origin of JPA entries in Baidu encyclopedia.
JPA is not too heavy and has no additional features. It will not be too light and the functions are enough, and some functions are often not satisfied due to the use of JPA. JPA looks so nice. However, JPA is a virtual thing. It is only a set of interface rules officially published, and there is no real implementation method. It is impossible to develop applications simply by using empty APIs such as official APIs. We still need to use some ORM framework packages to complete real tasks. So, is this too complicated. Why should we stick to other people's frameworks. You can either officially implement JPA so that users only pay attention to JPA. Or focus on using the ORM framework. As for how to call it, it is up to the ORM framework. Then JPA will lose its meaning. If it is implemented by the official JPA, it is actually just an additional ORM framework (officially implemented by the orm module called JPA) in the world ), or focus on using the ORM framework. That was in the past. There is no progress.
So where is the progress of JPA? The official website defines a set of APIs and clearly describes each part of the functions. You only need to know how to operate the database and understand the JPA specifications. Follow the JPA rules.
But this JPA is virtual. How can it become a truly useful thing. Of course, it is easy to do this by the original ORM vendor. They have accumulated in the ORM industry. They only implement the JPA function according to the JPA game rules.
As a result, the official JPA specification has been released, and the world is unified in terms of database operations. You can use ORM framework a or ORM framework B in the same way. In an instant, the world becomes smooth and there are not so many complicated things.
Another question: which companies are implementing this empty JPA? There is Hibernate (specifically, Hibernate Entity Manager. The well-known Hibernate has also passed the JPA compatibility certification, and the boss of the negative JPA is the inventor of Hibernate), JDO, Spring (Why does Spring come? Take a moment to learn about some specific Spring functions, such as Spring's ability), OpenJPA (this is an Apaceh project, but you still need to pay attention to it. If you are free, you 'd better learn how to use it), and Toplink.
Secondly, what is the relationship between JPA and EJB? What benefits does JPA bring to EJB. I believe you have followed JPA and are willing to pay attention to EJB. Pai_^