¿ìËÙÒµÎñͨµÀ

ʹÓÃAppFuseµÄÆ߸öÀíÓÉ: ѧϰJava¿ª·ÅÔ´Â빤¾ß²¢Ê¹ÓÃÕâЩ¹¤¾ßÌá¸ßÉú²úЧÂÊ - ±à³ÌÈëÃÅÍø

×÷Õß ØýÃû¼¼Êõ À´Ô´ NET±à³Ì ä¯ÀÀ ·¢²¼Ê±¼ä 2012-06-19
. <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Ϊ£º

Hibernate: select user0_.id as id1_, user0_.name as name0_1_, user0_.room_id as room3_0_1_, room1_.id as id0_, room1_.address as address1_0_ from user user0_ left outer join room room1_ on user0_.room_id=room1_.id where user0_.id=? outer-joinΪfalseµÄʱºò£¬Éú³ÉµÄ²éѯSQLΪ£ºHibernate: select user0_.id as id0_, user0_.name as name0_0_, user0_.room_id as room3_0_0_ from user user0_ where user0_.id=? Hibernate: select room0_.id as id0_, room0_.address as address1_0_ from room room0_ where room0_.id=?

²»¹ý×îºÃʹÓÃfetchÊôÐÔÀ´±íʾ£¬¼°fetch="join"»òÕßfetch="select"¡£

ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£º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ºÅ