package Org.Ajay.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import AjayBraindto.UserDetails;
public class Hibernatetest {
public static void main(String[] args) {
// TODO Auto-generated method stub
UserDetails userdetail=new UserDetails();
userdetail.setUserid(5);
userdetail.setUsername("Ajay pal");
SessionFactory sessionfactory=new
Configuration().configure().buildSessionFactory();
Session session=sessionfactory.openSession();
session.beginTransaction();
session.save(userdetail);
session.getTransaction().commit();
}
}
<session-factory>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">mcatopper</property>
<property name="show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<!-- Drop and re create schema on start up -->
<property name="hbm2dll.auto">create</property>
<mapping class="AjayBraindto.UserDetails"/>
@Entity
@Table(name="UserDetails")
public class UserDetails {
@Id
private int Userid;
private String Username;
public int getUserid() {
return Userid;
}
public void setUserid(int userid) {
Userid = userid;
}
public String getUsername() {
return Username;
}
public void setUsername(String username) {
Username = username;
}
}