Connecting eclipse + hibernate to Oracle (2)

Source: Internet
Author: User
2. create a people class, which is equivalent to a javabeanpackage COM. example. bean; public class people {private int ID; private string name; private string status; Public int GETID () {return ID;} public void setid (int id) {This. id = ID;} Public String getname () {return name;} public void setname (string name) {This. name = Name;} Public String getstatus () {return status;} public void setstatus (string status) {This. status = status ;}}
3. Create the people. HBM. xml file in the src directory to map to the people table in the database. <? XML version = "1.0" encoding = "UTF-8"?> <! Doctype hibernate-mapping public "-// hibernate/hibernate DTD ing DTD 3.0 // en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 

4. Create the hibernate. cfg. xml file in the src directory to connect to the database. <? XML version = "1.0" encoding = "UTF-8"?> <! Doctype hibernate-configuration public "-// hibernate/hibernate configuration DTD/EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 

5. create a help class to create and delete sessions, and get the session factory package COM. example. util; import Org. hibernate. hibernateexception; import Org. hibernate. session; import Org. hibernate. sessionfactory; import Org. hibernate. cfg. configuration; public class dbutil {Private Static final sessionfactory; @ suppresswarnings ("unchecked") public static final threadlocal session = new threadlocal (); static {sessionfactory = new configuration (). con Figure (). buildsessionfactory () ;}@ suppresswarnings ("unchecked") public static session currentsession () throws hibernateexception {session S = (Session) session. get (); If (S = NULL |! S. isopen () {S = sessionfactory. opensession (); Session. set (s);} return s;} public static void closesession () throws hibernateexception {session S = (Session) session. get (); Session. set (null); If (s! = NULL) S. Close ();} public sessionfactory getsessionfactory () {return sessionfactory ;}}

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.