-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: hibernate.hbm2ddl.auto not generating tables??
PostPosted: Sun Jan 01, 2012 12:14 pm 
Newbie

Joined: Sat Jan 01, 2011 4:31 am
Posts: 6
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...


Top
 Profile  
 
 Post subject: Re: hibernate.hbm2ddl.auto not generating tables??
PostPosted: Mon Jan 02, 2012 3:36 am 
Newbie

Joined: Sat Jan 01, 2011 4:31 am
Posts: 6
OK I added the mapping per class instead of package and it worked. only hibernate couldn't find my entities. I still didnt get to see the SQLs that created the tables.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.