Basics of Hibernate

Data mapping tools are used by developers to get rid of writing sql queries.

They are easy and provide all the functionality of sql queries and you dont have to remove the errors (,)(“) (‘) (+) from them.

Just define the beans and using the annotaions feature of hibernate you can easily map each column to their respective bean in the bean class itself..

Step 1 -example of the mapping: package example;


import java.io.Serializable;

import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id;

import javax.persistence.Table;

@Entity @Table(name = “STUDENTS”) public class Student implements Serializable {

public Employee() {

} @Id @Column(name = “STUDENT”)

private Integer student;

public Integer getStudent() { return student;

}

public void setStudent(Integer student) { this.student = student; }

}

Step -2 : Include these three libraries in your project.

1.hibernate-commons-annotations.jar 2.ejb3-persistence.jar

3.hibernate-annotations.jar

Step 3 : In the hibernate.cfg.xml, just do all the configurations for session factory.

Step 4 : Get the session as sessionFactory session = new AnnotationConfiguration().configure().buildSessionFactory(); Session currentSession= session.getCurrentSession(); Make an object od Student as

Student student = new Student();

student.setStudent(1);

currentSession.save(student);

150 150 Burnignorance | Where Minds Meet And Sparks Fly!