Announcement Announcement Module
Collapse
No announcement yet.
SessionFactory for Hibernate Issue (hbm2ddl.auto) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SessionFactory for Hibernate Issue (hbm2ddl.auto)

    I have tried two approaches for creating the SessionFactory that the HibernateTemplate uses.

    // loads the factory using Spring IoC from spring.xml
    SessionFactory sessionFactory = (SessionFactory) factory.getBean("mySessionFactory");

    OR

    // loads the factory directly and reads values from hibernate.cfg.xml
    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

    I am using Spring 1.2 and Hibernate 3.0.3. When I instantiate the factory directly, the <hbm2ddl.auto>create</hbm2ddl.auto> works properly. However, when I load the factory via Spring IoC, the hibernateProperties do not seem to be loading properly (specifically the hbm2ddl.auto):

    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.HSQL Dialect</prop>
    <prop key="show_sql">true</prop>
    <prop key="hbm2ddl.auto">create</prop>
    </props>
    </property>

    Has anyone else run into this type of problem?

  • #2
    Try adding schemaUpdate to your LocalSessionFactoryBean. E.g.:
    Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
       <property name="dataSource"><ref local="dataSource"/></property>
       <property name="configLocation"><value>classpath&#58;hibernate.cfg.xml</value></property>
       <property name="schemaUpdate"><value>true</value></property>
    </bean>

    Comment


    • #3
      Actually I found out the problem was this:

      <property name="hibernateProperties">
      <props>
      <prop key="hibernate.dialect">org.hibernate.dialect.HSQL Dialect</prop>
      <prop key="show_sql">true</prop>
      <prop key="hbm2ddl.auto">create</prop>
      </props>
      </property>

      i was missing the "hibernate." prefix. Notice the difference between the "hibernate.dialect" and the "hbm2ddl.auto".

      <prop key="hibernate.hbm2ddl.auto">create</prop> is the solution

      Comment


      • #4
        This shouldn't matter in my opinion. I use and forget hibernate prefix all the time ... ( it works both ways )

        thats weird

        Regards
        Vyas, Anirudh

        Comment


        • #5
          I'd like to re-iterate the solution here. You need a hibernate. in front of that particular parameter for it to work. I searched the whole web looking for why my tables weren't being generated. Thanks OP.

          Comment

          Working...
          X