30 lines
No EOL
707 B
Java
30 lines
No EOL
707 B
Java
package com.practice;
|
|
|
|
import org.hibernate.Transaction;
|
|
|
|
import org.hibernate.Session;
|
|
|
|
public class Main{
|
|
public static void main(String[] args){
|
|
|
|
Session session = HibernateUtil.getSessionfactory().openSession();
|
|
Transaction tx = null;
|
|
try{
|
|
tx = session.beginTransaction();
|
|
Student newStudent = new Student(2340, "rafay", 3.14);
|
|
session.save(newStudent);
|
|
tx.commit();
|
|
}
|
|
catch(Exception e){
|
|
if(tx != null){
|
|
tx.rollback();
|
|
}
|
|
e.printStackTrace();
|
|
}
|
|
finally{
|
|
session.close();
|
|
}
|
|
|
|
HibernateUtil.shutdown();
|
|
}
|
|
} |