Home  >  Article  >  Java  >  How does Java ORM work?

How does Java ORM work?

王林
王林forward
2023-04-24 23:40:061615browse

1.ORM mapping relationship

In actual development, programmers use object-oriented technology to operate data, but when storing data, they use a relational database, so Caused a lot of inconvenience. ORM can build a bridge between the object model and the tables of the relational database. Programmers can use the API to directly operate JavaBean objects to implement operations such as data storage, query, change and deletion.

java orm的原理是什么

2. Principle of running process

Convert classes or objects into SQL statements, and then operate the database through a third-party connection. Users no longer need to write SQL statements, ORM does it all for you.

3. Example

public class M_People
 
    {
 
 
 
        string _Pl_ID;
 
        [DataFieldAttribute("Pl_ID", "Int")]
 
        public string Pl_ID
 
        {
 
            get { return _Pl_ID; }
 
            set { _Pl_ID = value; }
 
        }
 
 
 
        int _PL_Age;
 
        [DataFieldAttribute("PL_Age", "Int")]
 
        public int PL_Age
 
        {
 
            get { return _PL_Age; }
 
            set { _PL_Age = value; }
 
        }
 
 
 
        string _Pl_Sex;
 
        [DataFieldAttribute("Pl_Sex", "nvarchar")]
 
        public string Pl_Sex
 
        {
 
            get { return _Pl_Sex; }
 
            set { _Pl_Sex = value; }
 
        }
 
 
 
        string _Pl_LoginName;
 
        [DataFieldAttribute("Pl_LoginName", "nvarchar")]
 
        public string Pl_LoginName
 
        {
 
            get { return _Pl_LoginName; }
 
            set { _Pl_LoginName = value; }
 
        }
 
 
 
        string _Pl_TrueName;
 
        [DataFieldAttribute("Pl_TrueName", "nvarchar")]
 
        public string Pl_TrueName
 
        {
 
            get { return _Pl_TrueName; }
 
            set { _Pl_TrueName = value; }
 
        }
 
 
 
        string _PL_Pwd;
 
        [DataFieldAttribute("PL_Pwd", "nvarchar")]
 
        public string PL_Pwd
 
        {
 
            get { return _PL_Pwd; }
 
            set { _PL_Pwd = value; }
 
        }
 
 
 
}

By customizing Attribute, we define a one-to-one correspondence between class attributes and database fields.

The above is the detailed content of How does Java ORM work?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete