I am new to Hibernate, reading this book \"Java persistence with Hibernate\" and I am trying to implement the example from there. So far my Ant build is successful, but when
The XML configuration file is by default expected to be in the root of your CLASSPATH.
You can select a different XML or path configuration file using:
SessionFactory sessionFactory;
try {
Logger log = Logger.getLogger(LOG);
final String HIB_CONFIG = "/path/to/hibernate.cfg.xml";
final File hibernate = new File(HIB_CONFIG);
log.info("Try to init SessionFactory: " + HIB_CONFIG);
// Create the SessionFactory from hibernate.cfg.xml
if (hibernate.exists()) {
log.info("File exists. Init with custom file.");
sessionFactory = new Configuration()
.configure(hibernate)
.buildSessionFactory();
} else {
log.info("File doesn't exist. Init with default project file.");
sessionFactory = new Configuration().configure().buildSessionFactory();
}
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
For more information look to session-configuration