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