SPRINGDATAJPA Getting Started 2

Source: Internet
Author: User
SPRINGDATAJPA Entity Overview

JPA provides a simple and efficient way to manage the mapping of Java Objects (POJO) to relational databases, which become JPA entities or short entities. Entities are typically associated with a single relational table in the underlying database, and an instance of each entity represents a row in a database table

SPRINGDATAJPA Entity Manager

The Entity Manager (Entitymanager) is used to manage entities in the system, which is a bridge between the entity and the database, which can be persisted into the database by invoking the relevant method of the entity manager, and the records in the database can be packaged into entity objects.

  The life cycle of an entity:

  As we can see, there are four states of an entity: New state, managed state, Free State, delete state.

A newly created object is in a new state, like creating a normal Java object, is a new object through the new object, after the creation of an assignment to the Entity manager's Persist method, you can let the entity State migration to the managed state, There are two things you can do at this time: INSERT statements insert data into the database and Mark entities as managed, and entities that are in the managed state are automatically committed to the database after the transaction commits if the property is modified. The managed state signifies being managed by the entity manager, and if we commit the transaction, then the state of the entity becomes Free State.

The so-called Free State, refers to the modification of the entity's properties will not trigger the database operation, this state is similar to the new state, the difference is that the Free State of the entity ID attribute is a value, and the entity ID of the new state is not a value. If you invoke the Close method of the entity manager or the clear method or detach, you can make the entity a Free State. Where the Close method is to close the entity manager, the clear method is that all entities of the Entity manager become free states, and detach can turn a single entity into a Free state. Entities that are in the managed state we can delete and can invoke the Remove method of the entity manager. But this time the system will not actually delete the data, the need to commit a transaction to delete the record.

SPRINGDATAJPA Getting Started 2

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.