hibernate配置文件中的properties元素
来源:互联网 发布:淘宝夏季情侣装 编辑:程序博客网 时间:2024/05/16 23:46
http://huihai.iteye.com/blog/1149635
假如现在有班级Class类与学生student类,但是在映射时,学生表关联的外键不是班级表的主键id,而是年级(grade)与班号(numb)这两个联合作外键,这样就要用到hibernate里的properties属性了。
Class.java类如下:
package cn.ehoo.hibernate.domain; /** *@author whp *@Email whp@ehoo.cn *@Aug 15, 2011 * */ public class Class { private Long id; private String grade; private String number; public String getGrade() { return grade; } public void setGrade(String grade) { this.grade = grade; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } }
Class.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="cn.ehoo.hibernate.domain"> <class name="Class" table="class"> <id name="id" type="long"> <generator class="native" /> </id> <properties name="name" unique="true" update="false"> <property name="grade" /> <property name="number" /> </properties> </class> </hibernate-mapping>Student.java类如下:
package cn.ehoo.hibernate.domain; /** *@author whp *@Email whp@ehoo.cn *@Aug 15, 2011 * */ public class Student { private Long id; private String name; private Class cla; public Class getCla() { return cla; } public void setCla(Class cla) { this.cla = cla; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }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="cn.ehoo.hibernate.domain"> <class name="Student" table="student"> <id name="id" type="long"> <generator class="native" /> </id> <many-to-one name="cla" class="Class" property-ref="name"> <column name="grade"></column> <column name="number"></column> </many-to-one> </class> </hibernate-mapping>
总之一句话, 当你在做关联时,两个表之间的外键关联由两个或以上的属性组成时, 就需要用到 properties元素。
0 0
- hibernate配置文件中的properties元素
- hibernate.properties配置文件
- hibernate.properties配置文件
- hibernate.properties配置文件位置
- hibernate 配置文件(hibernate.properties)
- Java中的properties配置文件
- hibernate 的 log4j.properties 配置文件
- hibernate 日志配置文件 log4j.properties
- Hibernate配置文件元素详解
- hibernate 配置文件(hibernate.properties)基本模板
- 获取 .properties 配置文件中的值
- 获取 .properties 配置文件中的值
- 读取配置文件*.properties中的信息
- Mybatis基础,mybatis核心配置文件properties元素
- Struts配置文件中的元素
- hibernate配置文件映射元素详解
- hibernate连接oracle9的配置文件(.properties)
- Hibernate配置文件hibernate.properties和hibernate.cfg.xml区别
- bombing:cocos2d-x内存管理机制-侧重调用
- CodeForces-228A-Is your horseshoe on the other hoof?
- 基于C++的灰度值方图处理
- [LeetCode]Merge Intervals
- 【OJ】Lake Counting (Poj 2386 // hzu.acmclub.com 11448)
- hibernate配置文件中的properties元素
- CodeForces-271A-Beautiful Year
- git基本操作
- block 1
- 框架学习六:ViewPagerIndicator
- DSP是什么
- nyoj.2 括号配对问题 20141014
- Android使用FileInputStream和FileOutputStream进行文件I/O操作
- Tomcat 7.0用户名与密码的设置问题