Professional Documents
Culture Documents
Home
Java
Frameworks
Database
Technology
Web Development
Build/Test Tools
Servers
PHP
Home
Hibernate
Hibernate4
Ask Questions?
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for. Ask your questions, our development team will try to give answers to your questions. 0
Tutorial Topics
Hibernate Framework Struts Framework Spring Framework XML Ajax JavaScript Java Web Services ( 1057 ) ( 836 ) ( 567 ) ( 196 ) ( 528 ) ( 109 ) ( 1806 ) ( 71 ) ( 145 ) ( 90 ) ( 503 ) ( 406 )
Jaime
In this tutorial you will learn about how to create an application of Hibernate 4.
Following steps that I have followed to create an application. These are as follows : Step 1 : At first I have created a table named person in MySQL. CET TBE`esn ( RAE AL pro` `d it1)NTNL, I` n(0 O UL `ae vrhr1)dfutNL, Nm` aca(5 eal UL PIAYKY(I` RMR E `d) )EGN=noBDFUTCASTltn NIEInD EAL HRE=ai1
Step 2 : Created a Java Project named coreHibernateExample (you can give the name as you wish). File -> New -> project / Java Project -> giveProjectName -> Finish (in this example I have given coreHibernateExample). Step 3 : Add the Hibernate jar files (to see how to add Hibernate's jar files click here ) Step 4 : Created a package named roseindia (you can give the name as you wish) under the src folder. Select src -> Right Click ->New -> package -> givePackageName -> Finish (in this exmaple I have given roseindia). Ste 5 : Created a file by following the name convention hibernate.cfg.xml (mandatory ) file under the src folder that the hibernate utilize to create a connection pool and the required environment setup. Select src -> Right Click -> New -> File ->hibernate.cfg.xml -> Finish. <xlvrin'.'ecdn=uf8? ?m eso=10 noig't-'> <DCYEhbraecniuainPBI !OTP ient-ofgrto ULC
www.roseindia.net/hibernate/hibernate4/firstHibernateApplication.shtml
1/5
27/02/13
"/HbraeHbraeCniuainDD/N -/ient/ient ofgrto T/E"
"tp/wwhbraeogddhbraecniuain30dd> ht:/w.ient.r/t/ient-ofgrto-..t"
<ient-ofgrto> hbraecniuain <eso-atr> ssinfcoy <rprynm=hbraecneto.rvrcas>o.yq.dcDie<poet> poet ae"ient.oncindie_ls"cmmsljb.rvr/rpry <rprynm=hbraecneto.r"jb:yq:/9.6.01:36dt poet ae"ient.oncinul>dcmsl/12181.330/aa <poet> /rpry <rprynm=hbraecneto.srae>ot/rpry poet ae"ient.oncinuenm"ro<poet> <rprynm=hbraecneto.asod>ot/rpry poet ae"ient.oncinpswr"ro<poet> <rprynm=hbraecneto.olsz"1<poet> poet ae"ient.oncinpo_ie>0/rpry <rprynm=so_q"tu<poet> poet ae"hwsl>re/rpry <rprynm=daet>r.ient.ilc.yQDaet/rpry poet ae"ilc"oghbraedaetMSLilc<poet> <rprynm=hbraecretssincnetcas>hed/rpry poet ae"ient.urn_eso_otx_ls"tra<poet>
Step 6 : Created a POJO class (persistent class) named Person.java in the package roseindia. pcaersida akg oeni;
pbi casPro ulc ls esn { iti; n d Srn nm; tig ae pbi Pro( ulc esn) { } pbi Pro(n i,Srn nm){ ulc esnit d tig ae spr) ue(; ti.d=i; hsi d ti.ae=nm; hsnm ae } pbi itgtd){ ulc n eI( rtr i; eun d } pbi vi stditi){ ulc od eI(n d ti.d=i; hsi d } pbi Srn gtae){ ulc tig eNm( rtr nm; eun ae } pbi vi staeSrn nm){ ulc od eNm(tig ae ti.ae=nm; hsnm ae } }
Ads by Google
Ads by Google
Ads by Google
Step 7 : Crated a file named ( you may follow the naming convention ClassName.hbm.xml ) person.hbm.xml under the src folder to map a Person Object to the database table named person <xlvrin'.'> ?m eso=10? <DCYEhbraempigPBI !OTP ient-apn ULC "/HbraeHbraeMpigDD30/N -/ient/ient apn T ./E" "tp/wwhbraeogddhbraempig30dd> ht:/w.ient.r/t/ient-apn-..t"
<ient-apn pcae"oeni" hbraempig akg=rsida> <ls nm=Pro"tbe"esn> cas ae"esn al=pro" <dnm=i"tp=it clm=I"> i ae"d ye"n" oun"d <eeao cas"sind/ gnrtr ls=asge">
www.roseindia.net/hibernate/hibernate4/firstHibernateApplication.shtml
2/5
27/02/13
<i> /d
Step 8 : Developed a code by writing a java class named PersonDetail in the package roseindia which will persist the Person object in the person table. pcaersida akg oeni;
ipr oghbraeSsin mot r.ient.eso; ipr oghbraeSsinatr; mot r.ient.esoFcoy ipr oghbraeTascin mot r.ient.rnato; ipr oghbraecgCniuain mot r.ient.f.ofgrto; ipr oghbraesrieSrieeity mot r.ient.evc.evcRgsr; ipr oghbraesrieSrieeityule; mot r.ient.evc.evcRgsrBidr
pbi casProDti ulc ls esneal { piaesai Ssinatr ssinatr; rvt ttc esoFcoy esoFcoy piaesai Srieeitysrieeity rvt ttc evcRgsr evcRgsr;
pbi sai vi mi(tig]ag) ulc ttc od anSrn[ rs { Ssinssin=nl; eso eso ul ty r { ty r { Cniuaincg=nwCniuain)adeore ofgrto f e ofgrto(.dRsuc( "esnhmxl)cniue) pro.b.m".ofgr(; srieeity=nwSrieeityule(.plStig( evcRgsr e evcRgsrBidr)apyetns cggtrpris).ulSrieeity) f.ePoete()bidevcRgsr(; ssinatr =cgbidesoFcoysrieeity; esoFcoy f.ulSsinatr(evcRgsr) } cth(hoal e) ac Trwbe x { Sse.r.rnl(Fie t cet ssinatr ojc.+e) ytmerpitn"ald o rae esoFcoy bet" x; trwnwEcpinnntaieErre) ho e xetoIIiilzrro(x; } ssin=ssinatr.pneso(; eso esoFcoyoeSsin)
Pro pro =nwPro(; esn esn e esn) Sse.u.rnl(IsrigRcr"; ytmotpitn"netn eod) Tascint =ssinbgnrnato(; rnato x eso.eiTascin) pro.eI() esnstd1; pro.eNm(Rsida) esnstae"oeni"; ssinsv(esn; eso.aepro) t.omt) xcmi(; Sse.u.rnl(Dn"; ytmotpitn"oe) }cth(xeto e { ac Ecpin ) Sse.u.rnl(.eMsae); ytmotpitnegtesg() }fnly{ ial ssincoe) eso.ls(; } }
www.roseindia.net/hibernate/hibernate4/firstHibernateApplication.shtml
3/5
27/02/13
}
Execute the example : You can execute the application as follows Go to your PersonDetail class Right Click -> Run As -> Java Application or, Select from the menu bar tab Run -> Run or, press the Ctrl button along with f11 i.e. CTRL + f11. Output : When you will run the application output will be as follows : 1. On console of Eclipse the output will be displayed as :
2. After Successfully execution of the code the record will be saved to the table that you had created in MySQL. as :
Previous
Index
Next
We're on
Follow
+142
More Tutorials from this section Hibernate 4 alias_to_entity_map C3P0 Hibernate Download Hibernate 4 entity hibernate
www.roseindia.net/hibernate/hibernate4/firstHibernateApplication.shtml
4/5
27/02/13
First Hibernate Application Hibernate 4 Tutorial Hibernate 4 Supported Databases List First Hibernate 4 Example with Eclipse Introduction To Hibernate 4.0 Hibernate Aggregate Functions Hibernate 4 Annotations Hibernate 4 Annotation Example Hibernate Architecture Hibernate avg() Function Hibernate C3P0 Difference Between cascade and inverse Keyword Hibernate Collection Mapping Hibernate Configuration File Hibernate count() Function
Ask Questions?
Your Em ail :
Subject (*):
S UBMI T
Services
Software Solutions
JSF Development Outsourcing ERP M-Commerce Flex Development
Website Development
Web Designing Web Redesigning Web Development Logo Design Web Design Packages Domain Registration
Content Development
Content Development Article Writing Blog Writing New s Writing SEO Copyw riting Technical Documentation Article Marketing
E-Commerce Solutions
CRM
Home
Privacy Policy
www.roseindia.net/hibernate/hibernate4/firstHibernateApplication.shtml
5/5