Hai friends,

i am inserting datas through Hibernate into my java program.I am using netbeans 7.1 IDE and apache tomcat 6.0 .I am not getting errors but data is not properly inserted into my mysql database.

Can any one please help me. i am waiting for you replys.

Thank You

hibernate.cfg.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jithin</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">traise</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping class="org.jith.java.dto.UserDetails"></mapping>
</session-factory>
</hibernate-configuration>



packagerg.jith.java.dto
UserDetails.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.jith.java.dto;

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

/**
*
* @author alfredannaalphonsa
*/
@Entity
public class UserDetails {
@Id
private int userId;
private String username;

public int getUserId() {
return userId;
}

public void setUserId(int userId) {
this.userId = userId;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

}

Packagerg.jith.hibernate
Class:HibernateTest.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.jith.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.jith.java.dto.UserDetails;

/**
*
* @author alfredannaalphonsa
*/
public class HibernateTest {



public static void Main(String[]args){
UserDetails user=new UserDetails();
user.setUserId(1);
user.setUsername("First Name");

SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
Session session=sessionFactory.openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();

}


}