Hibernate

adplus-dvertising
Another Java Files
Previous Home Next

sessionProvider.java

package r4r;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class SessionProvider {
static SessionFactory factory;
static
{
Configuration cfg=new Configuration().configure();
factory=cfg.buildSessionFactory();
}
public static Session getSession() {
return factory.openSession();
}
}

PersisTest.java

package mypack;

import java.util.*;
import org.hibernate.Session;
import org.hibernate.Transaction;
public class PersistTest {
public static void main(String[] args) {
Trainer tr=new Trainer("Rama");
Batch b1=new Batch("9 to 11","Core", "w/d",tr);
Batch b2=new Batch("12 to 3", "J2ee", "w/e",tr);
Batch b3=new Batch("9 to 12", "Hibernate", "w/e",tr);
Session s=SessionProvider.getSession();
Transaction t=s.beginTransaction();
s.save(b1);
s.save(b2);
s.save(b3);
t.commit();
s.close();
System.out.println("persisted.");
}
}
Previous Home Next