I am pretty new to Hibernate and I am working on a project where I would like to be manage my schema changes from within my code to allow for doing things like populating default values, etc. My application is a JSF 2.0 based web application that I am going to distribute via a war file. What I would like, is to use a ServletContextListener to install my database on application startup as well as perform any database upgrades as needed.
So here is my question, is there a way to use Hibernate to create my tables with with createSQLQuery? The problem is when I attempt to get a session using my HibernateUtil class, it tries to spin up all the mappings, which fail because the table don't yet exist. So, my question is can I do this without using hibernate.hbm2ddl.auto? As I said, I am pretty new with Hibernate, so if this is a dumb question I apologize ahead of time.
Thanks
Here is my HibernateUtil class
Code:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static
{
try
{
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
}
catch (Throwable ex)
{
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static void close()
{
if (sessionFactory != null)
sessionFactory.close();
}
public static SessionFactory getSessionFactory()
{
return sessionFactory;
}
}