Sunday, August 17, 2008

Hibernate First Impression

Now, lets talk about object persistence framework. It is Hibernate. How to generate tables in database from POJOs (Plain Old Java Objects). All that you need are:
1. Eclipse as IDE
2. MySQL 5 as Database
We also need other libraries such as:
1. Hibernate-3.*
2. MySQL-connector-java-5.*
3. Jakarta-commons
4. X-Doclet-1.*

To generate tables in database from POJOs with hibernate, we need mapping files (*.hbm.xml) for that POJOs. As example, User.java (a POJO) need User.hbm.xml that will be used to map that POJO with table in database. We also need a hibernate configuration file (hibernate.cfg.xml). It is needed to configure database properties with hibernate. In this example we will generate both of *.hbm.xml and hibernate.cfg.xml by using X-Doclet and Ant. Let's start it.

Firstly create database named ndung in MySQL.


Create a java project in Eclipse named HibernateExample. Create a new folder named lib. It is used to place our libraries. Move all libraries above to folder lib. So in the lib folder, there are 4 folders inside. Also add a properties file in the lib folder named lib.properties. This is an example, my lib.properties. It show my libraries configuration. Make it in your own. Also configure build path our project into these libraries.

lib.properties

In source folder make java package named com.ndung.model and com.ndung.main. We will place our POJOs in com.ndung.model and main file in com.ndung.main. Create java classes in com.ndung.model named User.java and HibernateUtil.java. In other side, create java class named Main.java in com.ndung.main.

User.java


HibernateUtil.java


Main.java

Now, we will generate User.hbm.xml and hibernate.cfg.xml automatically by using X-Doclet and Ant. Make two xml files in the project named properties.xml and build.xml.

properties.xml


build.xml

To run Ant based on our own build.xml file, in Eclipse menu bar click Window, click Show View menu item, and click Ant menu item. Ant panel will show up in the right of Eclipse. Right click on that panel, click Add Buildfiles. Choose build.xml to add from HibernateExample project. 4 menus will show up in that panel below HibernateExample. Double click on hibernatedoclet. It will generate hibernate mapping files and also a hibernate configuration file. Check out in source folder, there are 2 new xml files. They are User.hbm.xml in /com/ndung/model folder and hibernate.cfg.xml.

User.hbm.xml


hibernate.cfg.xml

Then double click on run in Ant panel. Now, check out your database.


Btw, Long Live My Indonesia...

257 comments:

«Oldest   ‹Older   201 – 257 of 257
Anonymous said...

buy xanax ritalin xanax drug interactions - xanax withdrawal 1mg/day

Anonymous said...

xanax cheap does 1mg xanax do - xanax dosage maximum

Anonymous said...

ambien pills buy ambien online overnight delivery - ambien overdose in cats

Anonymous said...

no prescription xanax can you overdose xanax - xanax extended release generic

Anonymous said...

buy ambien buy zolpidem no prescription usa - risks of ambien and pregnancy

Anonymous said...

xanax online Sacramento where to order xanax online - xanax side effects alcohol

Anonymous said...

buy xanax online legally how to buy xanax online legally - xanax good high blood pressure

Anonymous said...

buy ambien online ambien overdose child - buy ambien no rx

Anonymous said...

xanax online Arizona order xanax bars online - xanax side effects headache

Anonymous said...

xanax no prescription online xanax bars price street - order valium xanax online

Anonymous said...

order ambien online no prescription buy ambien online usa - ambien 10mg dosage

Anonymous said...

buy xanax without prescriptions drug abuse with xanax - xanax 605

Anonymous said...

ambien pharmacy buy cheap ambien no prescription - ambien and pregnancy first trimester

Anonymous said...

generic ambien online ambien long term use - ambience mall gurgaon hours

Anonymous said...

buy xanax xanax side effects for long term use - xanax 2mg alcohol

Anonymous said...

generic xanax El Paso purchase cheap xanax - taking 2mg of xanax

Anonymous said...

generic xanax Tennessee xanax side effects next day - xanax withdrawal insomnia

Anonymous said...

buy xanax online buy xanax online us - xanax side effects slurred speech

Anonymous said...

zolpidem drug ambien generic price walgreens - cost generic ambien walgreens

Anonymous said...

zolpidem online ambien side effects throwing up - much does generic ambien cr cost

Anonymous said...

cheap xanax xanax dosage yellow - buy xanax brand online

Anonymous said...

ambien no prescription generic ambien safe - generic medication ambien cr

Anonymous said...

buy ambien side effects mixing ambien xanax - ambien high blood pressure medication

Anonymous said...

cheapest ambien effexor xr ambien cr - maximum safe dosage ambien

Anonymous said...

buy alprazolam online xanax bars facts - buy xanax online illegal

Anonymous said...

xanax online Albuquerque xanax dosage compared to valium - xanax side effects memory

Anonymous said...

generic xanax Portland xanax withdrawal peak - xanax 2mg drugs.com

Anonymous said...

generic ambien long 10mg ambien kick - mail order ambien cr

Anonymous said...

cheapest xanax buy non generic xanax online - xanax bars street price

Anonymous said...

online xanax have you ever bought xanax online - generic xanax g3722

Anonymous said...

buy ambien ambien joint pain - ambien during pregnancy safe

Anonymous said...

buy xanax online buy xanax online cheapest - does xanax show up parole drug test

Anonymous said...

buy cheap ambien ambien zolpidem - buy ambien online from usa

Anonymous said...

generic xanax where to buy legit xanax online - xanax relieve anxiety

Anonymous said...

ambien no rx ambien cr 4 day trial - ambien zolpidem tartrate same

Anonymous said...

where can i buy xanax online using xanax for anxiety - xanax side effects to fetus

Anonymous said...

buy generic ambien ambien side effects erectile dysfunction - ambien and hiv medication

Anonymous said...

xanax online no prescription generic name for xanax - generic xanax blue pill

Anonymous said...

buy ambien ambien side effects tinnitus - ambien sleep driving cases

Anonymous said...

buy xanax online buy alprazolam in australia - generic name for xanax

Anonymous said...

buy xanax online no rx buy xanax us online - tranxene vs xanax side effects

Anonymous said...

buy ambien ambien overdose limit - where can you buy ambien online

Anonymous said...

buy xanax online xanax 3 mg pills - xanax bars anxiety

Anonymous said...

buy ambien ambien side effects uses - ambien drug card

Anonymous said...

generic ambien buy ambien overdose in dogs - ambien user reviews

Anonymous said...

buy xanax online does military drug test xanax - xanax brand online no prescription

Anonymous said...

buy ambien online no prescription generic ambien online + no prescription - ambien drug test false positives

Anonymous said...

buy xanax online xanax narcotic - xanax 2mg first time

Anonymous said...

buy ambien generic form ambien cr - ambien prozac drug interactions

Anonymous said...

buy xanax online xanax overdose prognosis - xanax .75 mg a day

Anonymous said...

xanax medication effects of 2mg xanax - clonazepam vs xanax high

Anonymous said...

buy ambien online no rx ambien and alcohol experience - generic ambien teva

Anonymous said...

buy xanax valium online florida much do 1mg xanax go street - order xanax mail

Anonymous said...

Үour аrticle has рroven beneficіаl to me peгѕοnallу.
It’s very helpful and yοu're clearly really experienced in this area. You possess popped my eye to be able to various opinion of this kind of subject matter with interesting and sound written content.
My page - Buy Valium

Anonymous said...

Υour οwn wгitе-up fеaturеs prоѵen bеneficial to me.
It’s really helpful anԁ you arе obѵiоusly vеry expeгienсed іn this field.
You get openеd our sіght for you to varying vіews on this
kіnd of subject matteг along wіth іntriguing, notаble аnd
solid cοntent.

Feеl fгee tο viѕit my site ::
Buy Valium Online

Anonymous said...



Here is my webpage; homepage

Anonymous said...



Take a look at my weblog :: homepage

«Oldest ‹Older   201 – 257 of 257   Newer› Newest»