日期:2014-05-16 浏览次数:20406 次
create table'group'( 'id' int(10) unsigned NOT NULL auto_increment, 'name' varchar(45)NOT NULL, PRIMARY KEY('id') ) create table 'user'( 'id' int(10) unsigned NOT NULL auto_increment, 'name' varchar(45) NOT NULL, 'group_id' int(10) unsigned default NULL, PRIMARY KEY('id'), KEY `FK_users_1` (`group_id`), CONSTRAINT `FK_users_1` FOREIGN KEY (`group_id`) REFERENCES `group` (`id`) )
<hibernate-mapping> <class name="com.stream.model.Group" table="group" catalog="test"> <id name="id" type="java.lang.Integer"> <column name="id" /> <generator class="identity" /> </id> <property name="name" type="java.lang.String"> <column name="name" length="45" not-null="true" /> </property> <!-- 以下是单向一对多的配置信息--> <set name="users" inverse="false" cascade="all"> <key> <!-- 指定user表中引用外键的是哪一列--> <column name="group_id"/> </key> <!--配置是与哪一个类之间的一对多 --> <one-to-many class="com.stream.model.User" /> </set> </class> </hibernate-mapping>
<class name="com.stream.model.User" table="user" catalog="test"> <id name="id" type="java.lang.Integer"> <column name="id" /> <generator class="identity" /> </id> <property name="name" type="java.lang.String"> <column name="name" length="45" not-null="true" /> </property> </class>