ʹÓÃAppFuseµÄÆ߸öÀíÓÉ: ѧϰJava¿ª·ÅÔ´Â빤¾ß²¢Ê¹ÓÃÕâЩ¹¤¾ßÌá¸ßÉú²úЧÂÊ - ±à³ÌÈëÃÅÍø
. <many-to-one name="room"17. column="room_id"18. class="com.hb3.pack_16.model.Room"
19. cascade="all"
20. outer-join="true"/>21. </class>22.
23.</hibernate-mapping>
²âÊÔ´úÂ룺 1.package com.hb3.pack_16;2.3.import java.io.IOException;4.import java.sql.SQLException;5. 6.import org.hibernate.Session;7.import org.hibernate.SessionFactory;8.import org.hibernate.Transaction;9.import org.hibernate.cfg.Configuration;10. 11.import com.hb3.pack_16.model.Room;12.import com.hb3.pack_16.model.User;13.14. 15.public class BusinessService {16. 17. public static void main(String[] args) throws IOException, SQLException {18.19. Configuration config = new Configuration().configure();20. SessionFactory sessionFactory = config.buildSessionFactory();21. Session session = sessionFactory.openSession();22. 23. Room room1 = new Room();24. room1.setAddress("NTU-M8-419");25. Room room2 = new Room();26. room2.setAddress("NTU-G3-302");27.28. User user1 = new User();29. user1.setName("shenbin");30. user1.setRoom(room1);31.32. User user2 = new User();33. user2.setName("chenyan");34. user2.setRoom(room1);35.36. User user3 = new User();37. user3.setName("yangye");38. user3.setRoom(room2);39. 40. Transaction tx = session.beginTransaction();41. session.save(user1);42. session.save(user2);43. session.save(user3);44. tx.commit();45. 46. User user = (User) session.load(User.class, new Integer(1));47. System.out.println(user.getName());48. System.out.println(user.getRoom().getAddress());49. 50.51. session.close();52. sessionFactory.close();53. }54.} hibernate3ѧϰ±Ê¼Ç(Ê®Æß)£ü¹ØϵӳÉ䣺¶à¶ÔÒ»(4)ʱ¼ä:2011-02-03ÔÚ<many-to-one>µÄÉ趨ÖУº cascade±íʾ²Ù×÷ʱµÄ¼¶Áª¹Øϵ¡£±íʾÖ÷¿Ø·½ÔÚ½øÐÐÔöɾ¸Ä²Ù×÷ʱ£¬±»¿Ø·½ÊÇ·ñ½øÐÐÏà¹Ø²Ù×÷¡£ outer-join±íʾ²éѯʱÊÇ·ñʹÓÃÍâÁ¬½Ó²éѯ·½Ê½¡£ outer-joinΪtrueµÄʱºò£¬Éú³ÉµÄ²éѯSQLΪ£º
²»¹ý×îºÃʹÓÃfetchÊôÐÔÀ´±íʾ£¬¼°fetch="join"»òÕßfetch="select"¡£ |
ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»! |