ϵͳѧϰhibernateÖ®ËÄ hibernate¶à¶ÔÒ»¹ØÁªÓ³Éä[Java±à³Ì]
¡¡¡¡±¾ÎÄ¡°ÏµÍ³Ñ§Ï°hibernateÖ®ËÄ hibernate¶à¶ÔÒ»¹ØÁªÓ³Éä[Java±à³Ì]¡±ÊÇÓÉÆßµÀÆæΪÄú¾«ÐÄÊÕ¼¯£¬À´Ô´ÓÚÍøÂçתÔØ£¬ÎÄÕ°æȨ¹éÎÄÕÂ×÷ÕßËùÓУ¬±¾Õ¾²»¶ÔÆä¹ÛµãÒÔ¼°ÄÚÈÝ×öÈκÎÆÀ¼Û£¬Çë¶ÁÕß×ÔÐÐÅжϣ¬ÒÔÏÂÊÇÆä¾ßÌåÄÚÈÝ£º
1¡¢¹ØÁªÓ³ÉäµÄ±¾ÖÊ:
* ½«¹ØÁª¹ØϵӳÉäµ½Êý¾Ý¿â,ËùνµÄ¹ØÁª¹ØϵÊǶÔÏóÄ£×ÓÔÚÄÚ´æÖеÄÒ»¸ö»ò¶à¸öÒýÓÃ
<many-to-one>»áÔÚ¶àµÄÒ»¶Ë¼ÓÈëÒ»¸öÍâ¼ü,Ö¸ÏòÒ»µÄÒ»¶Ë,Õâ¸öÍâ¼üÊÇÓÉ<many-to-one>
ÖеÄcolumnÊôÐÔ¶¨ÒåµÄ,¼ÙÈçºöÊÓÁËÕâ¸öÊôÐÔÄÇôĬÐíµÄÍâ¼üÓëʵÌåµÄÊôÐÔÒ»ÖÂ
<many-to-one>±êÇ©µÄ¶¨ÒåʾÀý:
* <many-to-one name="group" column="groupid"/>
1¡¢UserµÄPOJOÀà:
1public class User {
2
3¡¡¡¡private int id;
4
5¡¡¡¡private String name;
6
7¡¡¡¡private Group group;
8//Ê¡ÂÔsetter¡¢getter°ì·¨
9}2¡¢GroupµÄPOJOÀà:
1public class Group {
2
3¡¡¡¡private int id;
4
5¡¡¡¡private String name;
6//Ê¡ÂÔsetter¡¢getter°ì·¨
7}
3¡¢UserµÄÓ³ÉäÎļþUser.hbm.xml:
1<?xml version="1.0"?>
2<!DOCTYPE hibernate-mapping PUBLIC
3¡¡¡¡"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
4¡¡¡¡"">
5<hibernate-mapping>
6¡¡¡¡<class name="com.bjsxt.hibernate.User" table="t_user">
7¡¡¡¡¡¡¡¡<id name="id">
8¡¡¡¡¡¡¡¡¡¡¡¡<generator class="native"/>
9¡¡¡¡¡¡¡¡</id>
10¡¡¡¡¡¡¡¡<property name="name"/>
11¡¡¡¡¡¡¡¡ <many-to-one name="group" column="groupid"/>
12¡¡¡¡</class>
13</hibernate-mapping>
4¡¢GroupµÄÓ³ÉäÎļþGroup.hbm.xml:
1<?xml version="1.0"?>
2<!DOCTYPE hibernate-mapping PUBLIC
3¡¡¡¡"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
4¡¡¡¡"">
5<hibernate-mapping>
6¡¡¡¡<class name="com.bjsxt.hibernate.Group" table="t_group">
7¡¡¡¡¡¡¡¡<id name="id">
8¡¡¡¡¡¡¡¡¡¡¡¡<generator class="native"/>
9¡¡¡¡¡¡¡¡</id>
10¡¡¡¡¡¡¡¡<property name="name"/>
11¡¡¡¡</class>
12</hibernate-mapping>
¡¡¡¡ÒÔÉÏÊÇ¡°ÏµÍ³Ñ§Ï°hibernateÖ®ËÄ hibernate¶à¶ÔÒ»¹ØÁªÓ³Éä[Java±à³Ì]¡±µÄÄÚÈÝ£¬Èç¹ûÄã¶ÔÒÔÉϸÃÎÄÕÂÄÚÈݸÐÐËȤ£¬Äã¿ÉÒÔ¿´¿´ÆßµÀÆæΪÄúÍƼöÒÔÏÂÎÄÕ£º
±¾ÎĵØÖ·£º | ÓëÄúµÄQQ/BBSºÃÓÑ·ÖÏí! |