4

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 :)

2
  • Did you try enabling show-sql <prop key="hibernate.show_sql">true</prop> - It could help you . Commented Jan 3, 2012 at 13:35
  • IMHO using ddl can give unexpected results when refactoring your code... Consider managing your ddl via another mechanism, such as Liquibase. Commented Jan 6, 2012 at 20:08

2 Answers 2

13

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

DLL = Dynamic Link Library

DDL = Data Definition Language

Sign up to request clarification or add additional context in comments.

1 Comment

Oops indeed! Thanks for pointing that out it solved the problem :)
1

There's a typo in your code

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

in the solution

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.