¿ìËÙÒµÎñͨµÀ

ϵͳѧϰhibernateÖ®Áù£ºÒ»¶ÔÒ»Íâ¼ü¹ØÁªÓ³ÉäË«Ïò¹ØÁª - ±à³ÌÈëÃÅÍø

×÷Õß ØýÃû¼¼Êõ À´Ô´ NET±à³Ì ä¯ÀÀ ·¢²¼Ê±¼ä 2012-06-15

ϵͳѧϰhibernateÖ®Áù£ºÒ»¶ÔÒ»Íâ¼ü¹ØÁªÓ³ÉäË«Ïò¹ØÁª

ʱ¼ä:2011-08-26

hibernateÒ»¶ÔһΨһÍâ¼ü¹ØÁªÓ³É䣨˫Ïò¹ØÁªPerson<---->idcard£©

Ò»¶ÔһΨһÍâ¼ü¹ØÁªË«Ïò£¬ÐèÒªÔÚÁíÒ»¶Ë£¨idcard£©£¬Ìí¼Ó<one-to-one>±êÇ©£¬Ö¸Ê¾hibernateÈçºÎ¼ÓÔØ

Æä¹ØÁª¶ÔÏó£¬Ä¬Èϸù¾ÝÖ÷¼ü¼ÓÔØperson£¬Íâ¼ü¹ØÁªÓ³ÉäÖУ¬ÒòΪÁ½¸öʵÌå²ÉÓõÄÊÇpersonµÄÍâ¼üά»¤µÄ¹Øϵ£¬

ËùÒÔ²»ÄÜÖ¸¶¨Ö÷¼ü¼ÓÔØperson£¬¶øÒª¸ù¾ÝpersonµÄÍâ¼ü¼ÓÔØ£¬ËùÒÔ²ÉÓÃÈçÏÂÓ³É䷽ʽ£º

<one-to-one name="person" property-ref="idCard"/>

1¡¢PersonµÄPOJOÀࣺ

1public class Person {23¡¡¡¡private int id;45¡¡¡¡private String name;67¡¡¡¡private IdCard idCard;8//Ê¡ÂÔsetter¡¢getter·½·¨9}

2¡¢IdCardµÄPOJOÀࣺ

1public class IdCard {23¡¡¡¡private int id;45¡¡¡¡private String cardNo;67¡¡¡¡private Person person;8//Ê¡ÂÔsetter¡¢getter·½·¨9}

ϵͳѧϰhibernateÖ®Áù£ºÒ»¶ÔÒ»Íâ¼ü¹ØÁªÓ³ÉäË«Ïò¹ØÁª(2)

ʱ¼ä:2011-08-26

3¡¢PersonµÄÓ³ÉäÎļþPerson.hbm.xml

1<?xml version="1.0"?>2<!DOCTYPE hibernate-mapping PUBLIC3¡¡¡¡"-//Hibernate/Hibernate Mapping DTD 3.0//EN"4¡¡¡¡"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">5<hibernate-mapping>6¡¡¡¡<class name="org.apple.hibernate.Person" table="t_person">7¡¡¡¡¡¡¡¡<id name="id">8¡¡¡¡¡¡¡¡¡¡¡¡<generator class="native"/>9¡¡¡¡¡¡¡¡</id>10¡¡¡¡¡¡¡¡<property name="name"/>11¡¡¡¡¡¡¡¡<many-to-one name="idCard" unique="true"/>12¡¡¡¡</class>13</hibernate-mapping>

4¡¢IdCardµÄÓ³ÉäÎļþIdCard.hbm.xml

1<?xml version="1.0"?>2<!DOCTYPE hibernate-mapping PUBLIC3¡¡¡¡"-//Hibernate/Hibernate Mapping DTD 3.0//EN"4¡¡¡¡"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">5<hibernate-mapping>6¡¡¡¡<class name="org.apple.hibernate.IdCard" table="t_idcard">7¡¡¡¡¡¡¡¡<id name="id">8¡¡¡¡¡¡¡¡¡¡¡¡<generator class="native"/>9¡¡¡¡¡¡¡¡</id>10¡¡¡¡¡¡¡¡<property name="cardNo"/>11¡¡¡¡¡¡¡¡<one-to-one name="person" property-ref="idCard"/>12¡¡¡¡</class>13</hibernate-mapping>

ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!

·ÖÏíµ½£º ¸ü¶à

Copyright ©1999-2011 ÏÃÃÅÁèÖڿƼ¼ÓÐÏÞ¹«Ë¾ ÏÃÃÅÓÅͨ»¥Áª¿Æ¼¼¿ª·¢ÓÐÏÞ¹«Ë¾ All rights reserved

µØÖ·(ADD)£ºÏÃÃÅÈí¼þÔ°¶þÆÚÍûº£Â·63ºÅ701E£¨¶«ÄÏÈÚͨÅÔ£© Óʱà(ZIP)£º361008

µç»°£º0592-5908028 ´«Õ棺0592-5908039 ×ÉѯÐÅÏ䣺web@lingzhong.cn ×ÉѯOICQ£º173723134

¡¶ÖлªÈËÃñ¹²ºÍ¹úÔöÖµµçÐÅÒµÎñ¾­ÓªÐí¿ÉÖ¤¡·ÃöB2-20100024  ICP±¸°¸:ÃöICP±¸05037997ºÅ