title: Unable migrate using Flyway 1.6 in Spring application
body: <p>I have Roo-generated Spring MVC application connected to PostgreSQL using Hibernate. I am trying to integrate Flyway 1.6 as a bean into Spring application context. "Something prevents" migrations from being executed and I'm getting error on context initialization caused by Hibernate metadata validation.
  There are no problems performing migrations using Flyway 1.6 Maven plugin (clean, init, migrate).</p>
  
  <p>Integration of Flyway 1.5 (previous version) works just fine.</p>
  
  <p>What should I do in order to make Flyway 1.6 integrated migrations work?
  What additional configuration should I provide?</p>
  
  <p>Environment: Ubuntu 11.10, Springsource Tool Suite 2.9.1 (Eclipse 3.7.2), OpenJDK 6b23, Tomcat 7.0.23, PostgreSQL 8.4.9/9.1, Spring 3.0/3.1, Hibernate 3.6.4.Final, PostgreSQL Native Driver 8.4 JDBC3/4 build 702.</p>
  
  <p>pom.xml:
  </p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  ...
  &lt;dependencies&gt;
      ...
      &lt;dependency&gt;
          &lt;groupId&gt;com.googlecode.flyway&lt;/groupId&gt;
          &lt;artifactId&gt;flyway-core&lt;/artifactId&gt;
          &lt;version&gt;1.6&lt;/version&gt;
          &lt;classifier/&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;com.googlecode.flyway&lt;/groupId&gt;
              &lt;artifactId&gt;flyway-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;1.6&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;driver&gt;org.postgresql.Driver&lt;/driver&gt;
                  &lt;url&gt;jdbc:postgresql://localhost:5432/library&lt;/url&gt;
                  &lt;baseDir&gt;db/migration&lt;/baseDir&gt;
                  &lt;user&gt;library&lt;/user&gt;
                  &lt;password&gt;library&lt;/password&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          ...
      &lt;/plugins&gt;
  &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>database.properties:
  </p>
  
  <pre><code>database.password=library
  database.url=jdbc\:postgresql\://localhost\:5432/library
  database.username=library
  database.driverClassName=org.postgresql.Driver
  </code></pre>
  
  <p>persistence.xml:
  </p>
  
  <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
  &lt;persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;properties&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="validate"/&gt;
          &lt;property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/&gt;
          &lt;property name="hibernate.connection.charSet" value="UTF-8"/&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Spring context configuration:
  </p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans" ...&gt;
  &lt;context:property-placeholder location="classpath*:META-INF/spring/*.properties"/&gt;
  &lt;context:spring-configured/&gt;
  &lt;context:component-scan base-package="edu.sandbox.library"&gt;
      &lt;context:exclude-filter expression=".*_Roo_.*" type="regex"/&gt;
      &lt;context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/&gt;
  &lt;/context:component-scan&gt;
  
  &lt;bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"&gt;
      &lt;property name="driverClassName" value="${database.driverClassName}"/&gt;
      &lt;property name="url" value="${database.url}"/&gt;
      &lt;property name="username" value="${database.username}"/&gt;
      &lt;property name="password" value="${database.password}"/&gt;
      &lt;property name="testOnBorrow" value="true"/&gt;
      &lt;property name="testOnReturn" value="true"/&gt;
      &lt;property name="testWhileIdle" value="true"/&gt;
      &lt;property name="timeBetweenEvictionRunsMillis" value="1800000"/&gt;
      &lt;property name="numTestsPerEvictionRun" value="3"/&gt;
      &lt;property name="minEvictableIdleTimeMillis" value="1800000"/&gt;
      &lt;property name="validationQuery" value="SELECT version();"/&gt;
  &lt;/bean&gt;
  &lt;bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
  &lt;/bean&gt;
  &lt;tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/&gt;
  &lt;bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" depends-on="flyway" id="entityManagerFactory"&gt;
      &lt;property name="persistenceUnitName" value="persistenceUnit"/&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
  &lt;/bean&gt;
  &lt;bean class="com.googlecode.flyway.core.Flyway" id="flyway" init-method="migrate"&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
  &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>log:
  </p>
  
  <pre><code>...
  INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@19d03a4e: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.context.config.internalBeanConfigurerAspect,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,dataSource,transactionManager,org.springframework.transaction.config.internalTransactionAspect,entityManagerFactory,flyway]; root of factory hierarchy
  DEBUG com.googlecode.flyway.core.dbsupport.DbSupportFactory - Database: PostgreSQL
  DEBUG com.googlecode.flyway.core.Flyway - Schema: public
  DEBUG com.googlecode.flyway.core.util.ClassPathScanner - Scanning directory: file:/home/developer/projects/sandbox/t7-work/webapps/library/WEB-INF/classes/db/migration/
  DEBUG com.googlecode.flyway.core.util.ClassPathScanner - Scanning directory: file:/home/developer/projects/sandbox/t7-work/webapps/library/WEB-INF/classes/db/migration/
  INFO  org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'persistenceUnit'
  ...
  INFO  org.hibernate.tool.hbm2ddl.DatabaseMetadata - table not found: book
  INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@43a4181c: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.context.config.internalBeanConfigurerAspect,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,dataSource,transactionManager,org.springframework.transaction.config.internalTransactionAspect,entityManagerFactory,flyway]; root of factory hierarchy
  ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [/.../applicationContext.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in file [/.../applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: persistenceUnit] Unable to build EntityManagerFactory
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
  ...
  </code></pre>