MongoDB and spring integration (2) -- entity ing

Source: Internet
Author: User

 

The object ing in spring-data-MongoDB is through

Mongomappingconverter class. It can be annotated

The document for converting the Java class to MongoDB.
It has the following annotations:
@ ID-Unique Identifier of the document. It is objectid in MongoDB and is unique, consists of Timestamp + machine ID + process ID + auto-increment counter (ensure that IDs generated within the same second do not conflict.

@ Document-declare a Java class as a MongoDB document.

Specify the document corresponding to this class through the collection parameter.

@ Dbref-declares associations similar to relational databases. PS: currently, cascade storage is not supported. When you modify the values in the deref object in this instance, the instance cannot save the objects referenced by deref, it must be saved separately, such as the person and account in the following example.

@ Indexed-declare that this field requires an index. indexing can greatly improve the query efficiency.

@ Compoundindex-composite index statement, composite index can effectively improve the query efficiency of multiple fields.

@ Geospatialindexed-declare this field as an index of geographical information.

@ Transient-the field ignored by the ing. This field is not saved

MongoDB.

@ Persistenceconstructor-declares the constructor to instantiate the data retrieved from the database as an object. The input value of this constructor is the data retrieved from dbobject.

The following is an example of an official document:

Person class

@ Document (Collection = "person") @ compoundindexes ({@ compoundindex (name = "age_idx", Def = "{'lastname': 1, 'age ': -1} ")}) public class person <t extends address >{@ ID private string ID; @ indexed (unique = true) Private integer SSN; private string firstname; @ indexed private string lastname; private integer age; @ transient private integer accounttotal; @ dbref private list <account> accounts; private t address; Public Person (integer SSN) {This. SSN = SSN ;}@ persistenceconstructor public person (integer SSN, string firstname, string lastname, integer age, t address) {This. SSN = SSN; this. firstname = firstname; this. lastname = lastname; this. age = age; this. address = address ;}

Account class

 
@ Documentpublic class account {@ ID private objectid ID; private float total ;}

 

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.