2013-06-13 5 views
0

JPA 주석에 정의 된 기존 엔티티와 기존 데이터베이스간에 liquibase:diff을 수행하려고합니다.Liquibase에서 지속성 단위 이름을 참조하는 방법

@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에 정의를하고 난 그렇게 liquibase 내 퍼시스턴스 유닛을 참조 할 : 사실, 대신의 EntityManagerFactory를 정의하는 persistence.xml을를 사용하여, 나는 같은 자바 기반의 구성으로 봄을 사용하고 있습니다 그것은 diff를 만들 수 있습니다. http://thecliftonian.wordpress.com/2012/04/05/liquibase-2-0-3-with-hibernate-3-5-6-and-annotations/ 을 referenceUrl 업데이트하여 : : 블로그 게시물에 제안

<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 확장자를 사용하여 시도 <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." 

답변

1

블롭 올리기 해결 방법 통합의 패치 버전을 필요로하지만, 자신의 풀 요청하면서 liquibase-hibernate 코드베이스로 가져 왔지만 아직 릴리스로 만들지 못했다. 그래야 플러그인의 커스텀 빌드를 스스로 할 필요가있다.

+0

안녕하세요, http://forum.liquibase.org/topic/how-to-reference-a-persistence-unit-name-in-liquibase#49382000000741089에서 내 질문을 업데이트합니다. – Dimitri