I want to perform a
liquibase:diff
between an existing database and my entities defined in JPA annotations. Actually, instead of using a persistence.xml to define the entityManagerFactory, I am using Spring with Java based configuration as such : @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean(); entityManagerFactory.setDataSource(dataSource()); entityManagerFactory.setPersistenceUnitName("my-persistence-unit"); entityManagerFactory.setPackagesToScan("com.mycompany.entities"); entityManagerFactory.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); return entityManagerFactory; }
The entities are defined in com.mycompany.entities
and I want to reference my persistence unit in liquibase so it can make the diff.
<plugin> <groupId>org.liquibase</groupId> <artifactId>liquibase-maven-plugin</artifactId> <version>3.0.0-rc1</version> <configuration> <changeLogFile>src/main/resources/changelog/changelog-master.xml</changeLogFile> <diffChangeLogFile>src/main/resources/db/migration/changelog-${project.version}.xml</diffChangeLogFile> <driver>org.h2.Driver</driver> <url>jdbc:h2:D:/work/06-database/my-database;</url> <referenceUrl>src/main/resources/META-INF/persistence.xml</referenceUrl> <referenceDriver>org.h2.Driver</referenceDriver> <username>sa</username> <password></password> </configuration> </plugin>
I tried using liquibase-hibernate
extension as suggested in the blog post :http://thecliftonian.wordpress.com/2012/04/05/liquibase-2-0-3-with-hibernate-3-5-6-and-annotations/ by updating the referenceUrl : <referenceUrl>persistance:my-persistance-unit</referenceUrl>
but I have this exception :
Error setting up or running Liquibase: liquibase.exception.DatabaseException: Connection could not be created to src/main/resources/META-INF/persistence.xml with driver org.h 2.Driver. Possibly the wrong driver for the given database URL
So my question is how to How to reference a persistence unit name in Liquibase?
Is there a better way to achieve that?
Update : The javadoc of the referenceUrl says :
The reference database URL to connect to for executing Liquibase. If performing a diff against a Hibernate config xml file, then use <b>"hibernate:PATH_TO_CONFIG_XML"</b> as the URL. The path to the hibernate configuration file can be relative to the test classpath for the Maven project."