Hibernate ing Composition

Source: Internet
Author: User

Domain Models and relational data models have different starting points:

Domain Model: consists of program code. By refining the granularity of persistence classes, you can improve code reusability and simplify programming.

In the absence of data redundancy, we should minimize the number of tables and simplify the reference relationships between tables to improve data access speed.

Hibernate classifies persistence attributes into two types:
Value Type: No OID, and cannot be persisted independently. The Life Cycle depends on the life cycle entity type of the object of the persistence class, it can be persisted independently and has an independent life cycle (if the object type contains the value type, this value type is a component, although it is composed of two classes, the same database table is used in different databases)

Apparently, it cannot be used directly? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> keys + PGJyPgo8aW1nIHNyYz0 =" http://www.2cto.com/uploadfile/Collfiles/20140602/20140602090337227.png "alt =" \ ">

Component



Worker. java
package com.atguigu.hibernate.entities;public class Worker {private Integer id;private String name;private Pay pay;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Pay getPay() {return pay;}public void setPay(Pay pay) {this.pay = pay;}}
Worker. hbm. xml
 
 
     
          
               
                
            
           
               
            
                   
           
           
            
            
            
            
               
  
 

Pay. java
package com.atguigu.hibernate.entities;public class Pay {private int monthlyPay;private int yearPay;private int vocationWithPay;public int getMonthlyPay() {return monthlyPay;}public void setMonthlyPay(int monthlyPay) {this.monthlyPay = monthlyPay;}public int getYearPay() {return yearPay;}public void setYearPay(int yearPay) {this.yearPay = yearPay;}public int getVocationWithPay() {return vocationWithPay;}public void setVocationWithPay(int vocationWithPay) {this.vocationWithPay = vocationWithPay;}}

Parent attribute: the parent class private Worker worker is referenced in the component;
Pay. java
package com.atguigu.hibernate.entities;public class Pay {private int monthlyPay;private int yearPay;private int vocationWithPay;private Worker worker;public Worker getWorker() {return worker;}public void setWorker(Worker worker) {this.worker = worker;}public int getMonthlyPay() {return monthlyPay;}public void setMonthlyPay(int monthlyPay) {this.monthlyPay = monthlyPay;}public int getYearPay() {return yearPay;}public void setYearPay(int yearPay) {this.yearPay = yearPay;}public int getVocationWithPay() {return vocationWithPay;}public void setVocationWithPay(int vocationWithPay) {this.vocationWithPay = vocationWithPay;}}
Worker. java
 
 
     
          
               
                
            
           
               
            
                   
           
           
            
            
            
            
            
               
  
 


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.