---
title: "Hibernate中property-ref的使用,常用来解决遗留数据库One To Many关系"
author: "pengchua"
date: "2007-11-23T08:36:10Z"
tags: ["Hibernate", "XML"]
slug: "hibernate-property-ref-one-to-many"
draft: false
lastmod: "2007-11-23T08:36:10Z"
id: 142845
url: "https://pengchua.iteye.com/blog/142845"
---

1.如表Class(ClassID,Class\_No,ClassName)与Student(StudentID,studentName,Class\_No), 其中ClassID,studentID为主键 两个表是一对多的关系,而要求两个通过ClassNo来关联. 而一般的情况下是通过ClassID,放在student表中作为外键. 2.具体的Hibernate的配置文件如下: Class.hbm.xml: Student.hbm.xml: 3.注意点: property-ref属性一般用来解决遗留数据库One To Many关系的问题 property-ref(可选)被关联到此外键的类中的对应属性的名字,若没指定,使用被关联类的主键. property-ref=是不是数据库表中的字段名,而是定义的java类中的属性性名,一定要注意.