我希望在现有数据库和JPA注释中定义的实体之间执行一个liquibase:diff。实际上,我没有使用persistence.xml来定义entityManagerFactory,而是使用基于Java的配置的Spring:
@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());
Properties properties = new Properties();
properties.put("javax.persistence.transactionType", "RESOURCE_LOCAL");
properties.put("hibernate.hbm2ddl.auto", "validate");
properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
properties.put("hibernate.connection.url", "jdbc:h2:D:/work/06-database/my-database;");
properties.put("hibernate.format_sql", "true");
properties.put("hibernate.connection.username", "sa");
properties.put("hibernate.connection.password", "");
entityManagerFactory.setJpaProperties(properties);
return entityManagerFactory;
}实体是在com.mycompany.entities中定义的,我希望引用我在液化库中的持久性单元,这样它就可以进行区分。
<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>我尝试使用liquibase-hibernate扩展,如博客文章:http://thecliftonian.wordpress.com/2012/04/05/liquibase-2-0-3-with-hibernate-3-5-6-and-annotations/中建议的那样,方法是更新referenceUrl:<referenceUrl>persistance:my-persistance-unit</referenceUrl>,但我有这样的例外:
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那么,我的问题是如何在Liquibase中引用持久性单元名称?
是否有更好的方法来实现这一点?
更新: referenceURl的javadoc声明:
要连接到的用于执行Liquibase的引用数据库URL。如果对Hibernate配置xml文件执行diff,则使用"hibernate:PATH_TO_CONFIG_XML“作为URL。hibernate配置文件的路径可以相对于Maven项目的测试类路径。“
发布于 2013-06-14 15:18:33
您引用的blob帖子看上去像是在做一些工作--它需要一个补丁版本的集成,但是虽然它们的拉请求已经被引入了清算库-hibernate代码库,但我不认为它已经发布了,所以你需要自己做一个定制的插件。
https://stackoverflow.com/questions/17091942
复制相似问题