Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate does not create my tables

I'm having a weird problem using Spring and Hibernate. I started using Hibernate using this in hibernate.cfg.xml:

<property name="hbm2ddl.auto">create</property>

It worked fine, and Hibernate successfully created the tables needed in the database. Now I'm using Spring and my bean used for hibernate in applicationContext.xml looks like this:

<bean id="mySessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="myDataSource" />
    <property name="mappingResources">
        <list>
            <value>domain/Entity.hbm.xml</value>
            <value>domain/Service.hbm.xml</value>
            <value>domain/User.hbm.xml</value>
            <value>domain/Arcos.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.hbm2dll.auto">create</prop>
        </props>
    </property>
</bean>

I had to drop the tables created by Hibernate at some point but Spring doesn't create them. I tried with create-drop instead of create (just in case someone asks). My DB Schema changed since I used Hibernate and I'm using a lot of getBeans("..."); in my code so it kind of bother me to reuse my Hibernate-only version just to create the tables. I also could create the table by hand, but what would be the point of using these frameworks?

I'm sure I'm doing something wrong somewhere, but I cannot find it. The console prompt an error saying there is no table named "the name of the table", so it connects to the DB successfully.

Thanks for your time :)

like image 678
Max Avatar asked Dec 10 '22 03:12

Max


2 Answers

hibernate.hbm2dll.auto --> hibernate.hbm2ddl.auto

DLL = Dynamic Link Library

DDL = Data Definition Language

like image 174
JB Nizet Avatar answered Dec 11 '22 16:12

JB Nizet


There's a typo in your code

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

in the solution

like image 25
Aravind A Avatar answered Dec 11 '22 17:12

Aravind A