Hibernate Tool
Hibernate Tool
Step1:
Help->Eclipse Marketplace
Step2:
Find text box there type-> jboss ->go
Step3:
Jboss tools->install
Step4:
De-select All
Step5:
Install anyway
Step8:
Restart now
Step9:
Open Perspective
Step10:
Step2:
Go to file……
Step3:
Step4:
Step5:
Step6:
Step8:
Test connection
Step9:
next
Step10:
Finish
Step11:
Step12:
Step13:
Step14:
Step15:
Step16:
Select dialect
Step17:
Finish
Step18:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-
3.0.dtd">
<hibernate-configuration>
<session-factory>
<property
name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</pr
operty>
<property name="hibernate.connection.password">tiger</property>
<property
name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:ORC
L</property>
<property
name="hibernate.connection.username">scott</property>
<property
name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prope
rty>
</session-factory>
</hibernate-configuration>
Step2:
Step3:
Step4:
Step5:
Step6:
Step7:
Step8:
Step9:
Step10:
Select user
Step11:
Go to Exports tab
Step14:
Step15:
Note: Here you can select domain class, mapping file, dao class
Etc……………..
Sample Example:
<properties>
<project.build.sourceEncoding>UTF-
8</project.build.sourceEncoding>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!--
https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.20.Final</version>
</dependency>
<!--
https://mvnrepository.com/artifact/com.jslsolucoes/ojdbc6 -->
<dependency>
<groupId>com.jslsolucoes</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.1.0</version>
</dependency>
<!--
https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.18</version>
<scope>provided</scope>
</dependency>
</dependencies>
Step2:
Step5:
package in.nit.domain;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Employee implements java.io.Serializable {
@Id
private Integer id;
private String name;
Step6:
Dao class:
Interface:
package in.nit.dao;
import in.nit.domain.Employee;
Impl:
package in.nit.dao;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import in.nit.domain.Employee;
@Override
public int save(Employee emp) {
Transaction tx=null;
int id=0;
//create hibernate SessionFactory, Session Objects
Session ses=new
Configuration().configure("/in/nit/cfgs/hibernate.cfg.xml").buildSessi
onFactory().openSession();
tx=ses.beginTransaction();
//Save Object
try {
id=(Integer)ses.save(emp);
tx.commit();
}
catch(Exception e) {
tx.rollback();
e.printStackTrace();
}
return id;
}
Factory:
package in.nit.dao;
Step7:
SaveTest
package in.nit.test;
import in.nit.dao.EmployeeDao;
import in.nit.dao.EmployeeDaoFactory;
import in.nit.domain.Employee;
Output is: