Herbnate session.createsqlquery (SQL) and session.createquery (SQL) use

Source: Internet
Author: User

 Public classDistributedaoImplementsserializable{Privatesessionfactory sessionfactory;  PublicSession getsession () {returnsessionfactory.getcurrentsession (); }         Publicsessionfactory getsessionfactory () {returnsessionfactory; }         Public voidsetsessionfactory (sessionfactory sessionfactory) { This. Sessionfactory =sessionfactory; }           PublicTask gettask (Integer ID) {Session session= This. getsession (); Transaction Tran=session.begintransaction (); List<Task> datas = Session.createquery ("From TestMessage"). List (); //testmessage is a Java class, and this class corresponds to a table!        Tran.commit (); returndatas.get (ID); }     Public voidSavetask (Task Task) {Session Session= This. getsession (); Transaction Tran=session.begintransaction ();         Session.save (Task);    Tran.commit (); }     PublicList<task>Findalltask () {Session session= This. getsession (); Transaction Tran=session.begintransaction (); List<Task> datas = Session.createquery ("From Task"). List ();        Tran.commit (); returndatas; }         PublicList<task>Findallfinishedtask () {Session session= This. getsession (); Transaction Tran=session.begintransaction (); List<Task> datas = Session.createquery ("From Task where state=2"). List ();        Tran.commit (); returndatas; }         PublicList<task>findusertaskfinish (String Developname) {Session session= This. getsession (); Transaction Tran=session.begintransaction (); String SQL= "SELECT * from Task where task.taskid in (select Taskteam.taskid from Taskteam where taskteam.developname=\ '" + Developna Me + "\ ') and task.state=2"; List<Task> datas = (list<task>) session.createsqlquery (SQL). Addentity (Task.class). List ();        Tran.commit (); returndatas; }         PublicList<task>Findusertasknoparticipatetask (String Developname) {Session session= This. getsession (); Transaction Tran=session.begintransaction (); String SQL= "SELECT * from the task where task.taskid not in (select Taskteam.taskid from Taskteam where developname=\ '" + Developname + "\‘)"; List<Task> datas = (list<task>) session.createsqlquery (SQL).addentity (Task.class ). List ();//Must have Addentity () method, otherwise you cannot
Return the specific type, actually return is Object Tran.commit (); returndatas; } PublicList<task>findusertaskparticipating (String Developname) {Session session= This. getsession (); Transaction Tran=session.begintransaction (); String SQL= "SELECT * from Task where task.taskid in (select Taskteam.taskid from Taskteam where developname=\ '" + developname + "\ ') and task.state=1 "; List<Task> datas = (list<task>) session.createsqlquery (SQL). Addentity (Task.class). List (); Tran.commit (); returndatas; } PublicList<developingparty> Findtaskalluser (intTaskID) {Session Session= This. getsession (); Transaction Tran=session.begintransaction (); String SQL= "SELECT * from Developingparty where developingparty.developname in (select Taskteam.developingparty from Taskteam where Taskteam.taskid= "+ TaskID +") "; List<DevelopingParty> datas = session.createsqlquery (sql). Addentity (Developingparty.class). List (); Tran.commit (); returndatas; }}

Herbnate session.createsqlquery (SQL) and session.createquery (SQL) use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.