java2db

Connect oracle with hibernate in MyEclipse, NetBeans, RAD



Hibernate is a ORM (Object/Relational Mapping) framework.To connect oracle with hibernate , add the hibernate jar files to the libraries.

Basic requirements to Connect oracle with hibernate :

Connect oracle with hibernateSoftwares :

…….Java  (Download Java)
…….Oracle (Download Oracle)

Connect oracle with hibernateJar files: (Download Hibernate 4 jars)
…….antlr-2.7.7.jar
…….dom4j-1.6.1.jar
…….hibernate-commons-annotations-4.0.5.Final.jar
…….hibernate-core-4.3.6.Final.jar
…….hibernate-jpa-2.1-api-1.0.0.Final.jar
…….jandex-1.1.0.Final.jar
…….javassist-3.18.1-GA.jar
…….jboss-logging-3.1.3.GA.jar
…….jboss-logging-annotations-1.2.0.Beta1.jar
…….jboss-transaction-api_1.2_spec-1.0.0.Final.jar

…….ojdbc14.jar

Connect oracle with hibernateFiles :
…….EmployeeDetails.java
…….EmpBean.java
…….hibernate.cfg.xml
…….Employee.hbm.xml

 

 

Directory Structure

MyEclipse :

Connect oracle with hibernate

NetBeans :

Connect oracle with hibernate

 

 

Connect oracle with hibernateCreate new java project .

Connect oracle with hibernateAdd all the jar files to the libraries .

Connect oracle with hibernateCreate Employee table in the database and insert few records.

Connect oracle with hibernateCopy the four (two java,two xml) files .

Connect oracle with hibernateFinally , run the EmployeeDetails.java  file .

 

Note : Here we created EmpBean.java , EmployeeDetails.java and Employee.hbm.xml files in the <default package>.You can also create these files in a separate package (Ex : EmpApp) and do the following changes :

Connect oracle with hibernate Change 1 . In hibernate.cfg.xml : <mapping resource=”Employee.hbm.xml“/> to <mapping ….resource=”EmpApp/Employee.hbm.xml“/> .

Connect oracle with hibernate Change 2 . In Employee.hbm.xml : <class name=”EmpBean” table=”Employee”> to <class ….name=”EmpApp.EmpBean” table=”Employee”>

Connect oracle with hibernate Change 3 . Add the package name (package EmpApp; ) as a first line in the .java files.

 

Example code to  Connect oracle with hibernate :

EmployeeDetails.java (main class):

EmpBean.java (Bean class ) :

hibernate.cfg.xml  (Hibernate configuration file) :

Employee.hbm.xml (Mapping file) :

Create Employee table in Oracle data base :

Output :

Connect oracle with hibernate

Note : If you are running the above application , from command prompt , copy all 4 files in a folder and add the jar files to class path.




Related Posts :
How to Connect to Oracle from Liferay portlet ( Java Liferay and Oracle integration )
Call database in Jsp (Access Oracle , MySQL , PostgerSQL ,Db2 from Jsp)
Hibernate error user_sequences doesn’t exist in mysql ( resolved )
Connect DB2 with Hibernate 4 in MyEclipse,NetBeans,RAD
Connect PostgreSQL with Hibernate 4 in Myeclipse,NetBeans,RAD
Connect MySQL with Hibernate 4 in NetBeans,MyEclipse,RAD
Jdbc with Mysql in NetBeans and MyEclipse
Jdbc with PostgreSQL using MyEclipse and NetBeans
   [will not be published]



^ <