Why does Java need persistence?

Source: Internet
Author: User
Persistence stores Java Virtual Machine objects permanently, instead of ing databases into objects. Data is usually stored in databases. Of course, if you have a better storage system, it can also be mapped to storage devices in the system. This may require you to develop a persistence framework to persist a Java object. If it is persistent to the database, many ORM frameworks such as Hibernate and lightweight ibatis have emerged, which are good choices.
Currently, most databases are relational databases, while Java is an object-oriented language. It is obvious how to save an object-type data to relational databases? This requires the use of a powerful ORM framework to solve this problem.
For example, in the ibatis framework, as long as you configure sqlmapconfig and the corresponding sqlmap configuration file, as long as you save the object or update the object and can, you do not need to write SQL to operate the data during programming, during the search, object data is also found, rather than relational data. hibernate also inserts and obtains the corresponding data through the object set (para) and get () methods, which will not be described here, there are a lot of such explanations on the Internet and related books. If you are interested, you 'd better study the source code. The above are open-source frameworks and you can go online.

Java persistence is used to solve conflicts between relational databases and Object-based programming languages. persistence can convert records into objects. Before the emergence and prevalence of object databases, persistence is the best way to solve and avoid non-object operations on Object-type programming operation data. java is a fully object-oriented language. If you operate relational databases directly using Java, you will find that you have to write a lot of bad smell code to solve the communication problem between databases and languages. for example, there are two tables, student (ID, name, classid) and Class (ID, name). If you need to find the Class Name of the student whose ID is 1, you need to execute the following (that is, structured) query operations in your Java code:
Select class. name from class, student where student. ID = 1 and student. classid = Class. ID
The persistent code can be written as follows:
Student. querystudent (1). getclass ();
In the persistent code, the class is automatically mapped to the student object through one to many ing, which saves a lot of time for joint queries and unifies the code, completely changed to meet the object-oriented operation specifications. this is the biggest benefit of persistence.

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.