Hi guys,
I have done this before and I am not sure why its not working, I am working with hibernate 3.5. I need to generate tables using the hibernate.hbm2ddl.auto property set to create. I am suing @Entity annotations to define my entities and they compile alright. here is my hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sdac</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.current_session_context_class">managed</property>
<mapping package="com.administration.entities"/>
</session-factory>
</hibernate-configuration>
and here is how I create the session factory:
Code:
public class DAO {
@SuppressWarnings("unused")
private static final Logger log = Logger.getLogger(DAO.class);
@SuppressWarnings("unchecked")
private static final ThreadLocal tl = new ThreadLocal();
private static final SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
protected DAO() {
}
@SuppressWarnings("unchecked")
public static Session getSession() {
Session session = (Session) DAO.tl.get();
if (session == null) {
session = sessionFactory.openSession();
DAO.tl.set(session);
}
return session;
}
}
and I have a class that extends DAO and has a main and just calls getSession() method. I thought the tables should be generated on the fly as soon as we instantiate the sessionfactory().
Previously i was using hibernate and springs hibernate template and their configuration. So may be i am missing something.
Thanks in advance.
Mahdi...