Explanation of annotations in mapping MongoDB in spring

Source: Internet
Author: User

The entity mappings in Spring-data-mongodb are implemented by Mongomappingconverter this class. It can be annotated to convert the Java class to a MongoDB document.

It has the following types of comments:

@Id-The unique identification of the document, which is unique in MongoDB, is the only one that consists of a timestamp + machine ID + process id+ self-increment counter (to ensure that the Id generated in the same second does not conflict) is Objectid.

@Document-Declare a Java class as a document of MongoDB, and you can specify the corresponding document for this class through the collection parameter. @Document (collection= "MongoDB") MongoDB correspondence table

@DBRef-declares an association relationship similar to a relational database. PS: Cascade saving function is not supported, when you modify the value inside the Deref object in this instance, saving this instance alone cannot save the object referenced by Deref, it should be saved separately, such as the person and account in the example below.

@Indexed-declares that the field needs to be indexed, and indexing can greatly improve query efficiency.

@CompoundIndex-Compound index Declaration, composite index can effectively improve the query efficiency of multiple fields.

@GeoSpatialIndexed-declares that the field is an index of geographic information.

@Transient-The field that the mapping ignores is not saved to MongoDB.

@PersistenceConstructor-Declares a constructor to instantiate the data taken from the database as an object. The value passed in by the constructor is the data taken from the DBObject

Explanation of annotations in mapping MongoDB in spring

Related Article

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.