µ±Ç°Î»ÖãºÆßµÀÆæ ¡ú ÎÄÕÂ×ÊѶ ¡ú ±à³Ì¼¼Êõ ¡ú Java±à³Ì
ÈÕÆÚ£º2011-03-22 16:13:00  À´Ô´£º±¾Õ¾ÕûÀí

ϵͳѧϰ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±à³Ì]¡±µÄÄÚÈÝ£¬Èç¹ûÄã¶ÔÒÔÉϸÃÎÄÕÂÄÚÈݸÐÐËȤ£¬Äã¿ÉÒÔ¿´¿´ÆßµÀÆæΪÄúÍƼöÒÔÏÂÎÄÕ£º
  • ϵͳѧϰhibernateÖ®Ò»:²Ù×÷hibernateÖеÄSchemaExportÉú³ÉÊý¾Ý
  • ϵͳѧϰhibernateÖ®¶þ SessionÖÐloadºÍget
  • <b>ϵͳѧϰhibernateÖ®Èý transient¡¢persistent¡¢detachedÇé¿ö</b>
  • ϵͳѧϰhibernateÖ®ËÄ hibernate¶à¶ÔÒ»¹ØÁªÓ³Éä
  • ±¾ÎĵØÖ·£º ÓëÄúµÄQQ/BBSºÃÓÑ·ÖÏí!
    • ºÃµÄÆÀ¼Û¡¡Èç¹ûÄú¾õµÃ´ËÎÄպ㬾ÍÇëÄú
        0%(0)
    • ²îµÄÆÀ¼Û¡¡Èç¹ûÄú¾õµÃ´ËÎÄÕ²¾ÍÇëÄú
        0%(0)

    ÎÄÕÂÆÀÂÛÆÀÂÛÄÚÈÝÖ»´ú±íÍøÓѹ۵㣬Óë±¾Õ¾Á¢³¡Î޹أ¡

       ÆÀÂÛÕªÒª(¹² 0 Ìõ£¬µÃ·Ö 0 ·Ö£¬Æ½¾ù 0 ·Ö) ²é¿´ÍêÕûÆÀÂÛ
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .