Hibernate and Java hello example

Step 1:  Open netbeans
File> New Project >java web> web application .click next
Project name : hibernatehello .click next . again click nextnow select framework : hibernate . click finish

Step 2: Now hibernate.cfg.xml file opens edit this line change the database name if required in am using hibernate 

jdbc:mysql://localhost:3306/mysql

after edit:

jdbc:mysql://localhost:3306/hibernate

make sure that this database should exists 
complete code of hibernate.cfg.xml

   org.hibernate.dialect.MySQLDialectcom.mysql.jdbc.Driverjdbc:mysql://localhost:3306/hibernaterootabhicreatetrue

Step 3:
Make a java class named student and copy the below code.(Student.java)

package one;
public class Student {
private Integer roll;
  private String name;
  public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getRoll() {
        return roll;
    }
    public void setRoll(Integer roll) {
        this.roll = roll;
    }
    public Student(Integer roll, String name) {
        this.roll = roll;
        this.name = name;
    }
    public Student() {
    }
}

Step 4:
Now right click on the folder and select hibernate mapping wizard
File Name: student.hbm .click next


class to map: one.Student .click finish
code in student.hbl


  

Step 5:
Again right click on package “one” select HibernateUtil.java
name this class as HibernateUtil and just click finish.
now last step:
copy this code in index.jsp









    
        
        JSP Page
    
    
        

Hello World!