Hibernate uses SQL statements directly

xiaoxiao2021-04-08  371

1. Create SQL STRINGBUFFER BUFF = New StringBuffer (); buff .append ("SELECT M.ID, M.MEMBER_NAME, B.SEX, B.BIRTHDAY, B.CONTACT_PROVINCE, B.CONTACT_CITACTACTACTACTACT_PPPPpend (" b.incoming, b.stature, b.self_description, b.self_description_approved, b.default_photo_path "); buff.append (" from member m "); buff.append (" inner join member_basic_profile b on b.member_id = m.id "); Buff.append (" Inner Join Favorite f on f.member_id = m.id "); buff.append (" where m.id =: memberid "); buff.append (" ORDER BY B.DEFAULT_PHOTO DESC, f.create_time desc "); GET_MY_FAVORITES = buff.toString (); 2, create a session, and execute SQL, and implement paging Session session = HibernateManager.getCurrentSession (); Query q = session.createSQLQuery (GET_OTHER_FAV); q.setInteger ( "MEMBERID", FavoriteID; if (Startrow! = null && fetchsize! = null) {q.setfirstResult (startrow); Q.SetMaxResults (fetchsize);}

3. Read data list result = new arraylist (); for (iTerator iter = Records.Item (); it.hasnext ();) {Object [] row = (object []) iter.next (); memberext EXT = New MemberExt (); // Member Extension Class MemberBasicProfile Profile = New MemberbasicProfile ();

EXT.SETMEMBERBASIICPROFILE (profile); hibernateHelper.Getint (row [0])); ext.setmembername (String) Row [1]);

转载请注明原文地址:https://www.9cbs.com/read-132819.html

New Post(0)