Hibernate advanced Apps

Source: Internet
Author: User

    • The relationship between data model and domain model
      • Domain model is an analytic model, which helps demand analysts and users to understand real business tools, describes the business design of the questions and their relationship, it is the product of demand analysis. The domain model is a powerful tool for the requirement analyst to communicate with the user, the concept that the requirement analyst and the user understand together, is the language that communicates with each other.
      • The data model is a part of system design and implementation, which describes the implementation of user requirements in data structure.
      • Conceptual model design in the data model is similar to the domain model, and the lack of a more extensive description between entities. The domain model design does not take into account the management of the data, only the relationship between the entity and the entity involved in the business description.
    • Many-to-one one-way correlation
    • Many-to-one bidirectional correlation
    • A pair of primary key associations
    • One-to-one foreign key association
    • Many-to-many association relationships: you need to save many-to-many mappings from another table
    • Cascading operations: Primary foreign KEY constraints are often used in database operations to protect the consistency of data operations. For example, in a one-to-two relationship between a citizen table and a ID card, it is not allowed to delete a citizen's information separately from the citizen table, and it is necessary to delete the associated information in the Identity card table, which means that the operation of two tables needs to be performed simultaneously.
      • Cascading operations (cascade) typically refer to whether the associated object (the accused) is synchronized when the save/update or delete operation is performed by the primary control party.

 

  • Entity Integration Relationship Mapping
    • Inheritance is an important object-oriented feature that is persisted in hibernate with object-oriented thinking. So in hibernate, the objects of the entities mapped by the data table can also have process relationships,
    • 3 Inheritance Mappings: The class inheritance tree is mapped into a table, each sub-class is mapped into a table, and each concrete class is mapped into a single table;
  • The class inheritance tree is mapped into a table:
    • <!---Class inheritance tree mapping configuration--> Package= "Com.mr.person" > <className= "Person" table= "Tab_person" > <id name= "id" > <generatorclass= "Native"/> </id> <!--declares a discriminator--<discriminator column= "type" type= "Strin G "/> <!--Mapping own properties--<property name=" name "not-NULL= "true"/> <property name= "Age" type= "int"/> <property name= "Sex" type= "string"/> &L t;!        --declaration subclass--<subclass name= "student" discriminator-value= "Students" > <property name= "School" > </subClass> <subclass name= "staffer" discriminator-value= "Staff" > <property NA Me= "Company" > </subclass> </class>
    • The class inheritance tree is mapped into a table with a special restriction, that is, those fields that are mapped by sub-class properties, such as the school field in the student table, cannot have a non-empty limit, otherwise it will cause hibernate data to fail to add.
    • Create Addperson, and in the main () method use the session's Save () method to save the student entity object and the employee entity object separately, the key code is as follows:
    • //Hibernate persistent OperationSession =hibernateinitialize.getsession (); Session.begintransaction (); //things Open
      Student Student =NewStudent (); Student.setname ("Xiao Ming"); Student.setage ("12"); Student.setsex (Male); Student.setschool ("Hope Primary School Tomorrow"); Session.save (student);
      Staffer staffer=NewStaffer ("Xiao Hong", 25, "female"); Staffer.setcompany ("Tomorrow's Technology"); Session.save (staffer);
      Session.gettransaction (). commit (); //Things to submit

  • Each subclass is mapped into a table: each subclass is mapped to a table, and two sub-class mapped tables are linked to the superclass-mapped data table by a primary key, creating a one-to-one relationship.
    • <!--mapping configuration for each subclass--> Package= "Com.mr.person" > <className= "Person" table= "Tab_person" > <id name= "id" > <generatorclass= "Native"/> </id> <!--declares a discriminator--<discriminator column= "type" type= "Strin G "/> <!--Mapping own properties--<property name=" name "not-NULL= "true"/> <property name= "Age" type= "int"/> <property name= "Sex" type= "string"/> &L t;!            --declaration subclass--<joined-subclass name= "Student" table= "tab_student" > <key column= "id"/> <property name= "School"/> </joined-subclass> <joined-subclass name= "staffer" table= "Tab_staffer" > <key column= "id"/> <property name= "Company"/> </join Ed-subclass> </class>

  • Each concrete class map becomes a table: each concrete class is mapped into a table, and each child class's mapping table contains the fields of the inherited parent class property mappings
    • <!--map configuration for each specific class-
       Package= "Com.mr.person" > <className= "Person"Abstract= "true" > <!--because the parent class does not need to map the data table, set the abstract property to true--> <id name= "id" > <!--Set the primary key generation policy to manual Assignment, the ID of the data needs to be set in the setter method in the Entity object--<generatorclass= "Assigned"/> </id> <!--declares a discriminator--<discriminator column= "type" type= "Str ing "/> <!--Mapping own properties--<property name=" name "not-NULL= "true"/> <property name= "Age" type= "int"/> <property name= "Sex" type= "string"/> &L t;! --Declaration subclass-<!--union-subclass element for mapping concrete classes to a table--<union-subclass name= "Student" table= "Tab_stu Dent "> <property name=" School "/> </union-subclass> <union-subclass na Me= "staffer" table= "Tab_staffer" > <property name= "Company"/> </union-subclass> </class>

Hibernate advanced Apps

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.