0

我想liquibase:diff在现有数据库和我在 JPA 注释中定义的实体之间执行一个。实际上,我没有使用 persistence.xml 来定义 entityManagerFactory,而是使用 Spring 和基于 Java 的配置:

    @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;
  }

实体是在 liquibase 中定义的com.mycompany.entities,我想在 liquibase 中引用我的持久性单元,以便它可以产生差异。

<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/ by更新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 说:

  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."
4

1 回答 1

2

您引用的 blob 帖子看起来他们有一个需要修补版本的集成的解决方法,但是虽然他们的拉取请求已被引入 liquibase-hibernate 代码库,但我不相信它已经发布了所以您需要自己进行插件的自定义构建。

于 2013-06-14T15:18:33.177 回答