单向一对一外键关联xml配置

po类Student

package com.hibernate.demo.po;

public class Student {
	private int id;
	private String name;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
}

 po类 学生卡类(StuIdCard)

package com.hibernate.demo.po;

public class StuIdCard {
	private int id;
	private String num;
	private Student student;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getNum() {
		return num;
	}
	public void setNum(String num) {
		this.num = num;
	}
	public Student getStudent() {
		return student;
	}
	public void setStudent(Student student) {
		this.student = student;
	}
	
}

Student.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.hibernate.demo.po">
    <class name="Student">
       <id name="id">
       		<generator class="native"/>
       </id>
       <property name="name"/>
    </class>
</hibernate-mapping>

 

StuIdCard.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.hibernate.demo.po.StuIdCard">
        <id name="id">
        	<!-- generate optimal identity strategy according to the configured dialect -->
            <generator class="native"/>
        </id>
        <property name="num"/>
        <many-to-one name="student" column="studentId" unique="true"></many-to-one>
    </class>
</hibernate-mapping>

 

 

你可能感兴趣的:(xml 一对一 外键关联)