I am using JDK 1.7 (with Derby database), Hibernate-release-4.0.0.CR6, and Eclipse Indigo SR1. I am unable to see how I can use a non-deprecated function in this code. The problem is that the line
SessionFactory sessionFactory = config.buildSessionFactory();
gives a deprecation error for buildSessionFactory(). What alternative can I use?
-----------------------------------------------------------------------
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class TestEmployee {
public static void main(String[] args) {
Configuration config = new Configuration();
config.addAnnotatedClass(Employee.class);
config.configure(); // read the file hibernate.cfg.xml
new SchemaExport(config).create(true, true);
Employee emp1 = new Employee();
Employee emp2 = new Employee();
emp1.setEmpID(150);
emp1.setEmpName("Janet Jones");
emp1.setEmpEmailAddress("
[email protected]");
emp2.setEmpID(250);
emp2.setEmpName("Billy Furtado");
emp2.setEmpEmailAddress("
[email protected]");
SessionFactory sessionFactory = config.buildSessionFactory();Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(emp1);
session.save(emp2);
session.getTransaction().commit();
session.close();
}
}