Hi
I am new to hibernate.
I am using the HibernateUtil class as below:
Code:
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
System.out.println("Did not enter the try block");
try {
// Create the SessionFactory from hibernate.cfg.xml
Configuration cfg = new Configuration();
System.out.println("got a Cfg");
cfg.configure("/WEB-INF/hibernate.cfg.xml");
System.out.println("configured cfg");
return cfg.buildSessionFactory();
//return (new Configuration().configure("/WEB-INF/hibernate.cfg.xml")).buildSessionFactory();
} catch (Error err) {
err.printStackTrace();
throw new ExceptionInInitializerError();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.out.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
} finally {
System.out.println("in finally");
throw new ExceptionInInitializerError();
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
After running the code, in the log i see the syss out statement
"Did not enter the try block"
but i do not see the
"got a Cfg"
i.e. Control is stuck insie the new Configuration call.
No Exception thrown.
No Error thrown
Does not end up in the finally part.
Can anyone please help me know what is wrong with the code?