Problem using liquibase from Java with Derby Embedded

I’m making Liquibase migration using groovy script.


I have a code like

  1. def migrate() {

  2.         def changeLog = "com/cadence/mdv/ngv/db.changelog.xml"
  3.         Sql db = Sql.newInstance(profile.dbUrl, profile.dbUser, profile.dbPassword, profile.dbDriver)


  4.         Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(db.connection))


  5.         def liquibase = new Liquibase(changeLog
  6.                 , new ClassLoaderResourceAccessor()
  7.                 , database
  8.         )
  9.         liquibase.update(null)

  10. }
But I receive exception


  1. liquibase.exception.MigrationFailedException: Migration failed for change set com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-31::pavelber (generated):
  2.      Reason: liquibase.exception.DatabaseException: Error executing SQL ALTER TABLE APP.ACTION_ATTRIBUTES ADD CONSTRAINT FKD1111B00C05F2ED6 FOREIGN KEY (RUN_ID) REFERENCES APP.RUNS (ID) ON UPDATE NO ACTION ON DELETE NO ACTION: 'ALTER TABLE' cannot be performed on 'APP.ACTION_ATTRIBUTES' because it does not exist.:
  3.           Caused By: Error executing SQL ALTER TABLE APP.ACTION_ATTRIBUTES ADD CONSTRAINT FKD1111B00C05F2ED6 FOREIGN KEY (RUN_ID) REFERENCES APP.RUNS (ID) ON UPDATE NO ACTION ON DELETE NO ACTION: 'ALTER TABLE' cannot be performed on 'APP.ACTION_ATTRIBUTES' because it does not exist.:
I see that in the list of my changesets (output by liquibase) ..
  1. INFO 8/20/12 4:08 PM:liquibase: Successfully acquired change log lock
  2. INFO 8/20/12 4:08 PM:liquibase: Creating database history table with name: DATABASECHANGELOG
  3. INFO 8/20/12 4:08 PM:liquibase: Reading from DATABASECHANGELOG
  4. INFO 8/20/12 4:08 PM:liquibase: Reading from DATABASECHANGELOG
  5. INFO 8/20/12 4:08 PM:liquibase: ChangeSet com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-1::pavelber (generated) ran successfully in 56ms
  6. INFO 8/20/12 4:08 PM:liquibase: ChangeSet com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-2::pavelber (generated) ran successfully in 29ms
  7. INFO 8/20/12 4:08 PM:liquibase: ChangeSet com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-3::pavelber (generated) ran successfully in 42ms
  8. INFO 8/20/12 4:08 PM:liquibase: ChangeSet com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-4::pavelber (generated) ran successfully in 29ms
  9. INFO 8/20/12 4:08 PM:liquibase: ChangeSet com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-5::pavelber (generated) ran successfully in 190ms
  10. INFO 8/20/12 4:08 PM:liquibase: ChangeSet com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-6::pavelber (generated) ran successfully in 32ms
  11. INFO 8/20/12 4:08 PM:liquibase: ChangeSet com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-7::pavelber (generated) ran successfully in 26ms
  12. INFO 8/20/12 4:08 PM:liquibase: ChangeSet com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-8::pavelber (generated) ran successfully in 23ms
  13. INFO 8/20/12 4:08 PM:liquibase: ChangeSet com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-9::pavelber (generated) ran successfully in 15ms
  14. INFO 8/20/12 4:08 PM:liquibase: ChangeSet com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-10::pavelber (generated) ran successfully in 31ms
  15. INFO 8/20/12 4:08 PM:liquibase: ChangeSet com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-11::pavelber (generated) ran successfully in 26ms
  16. INFO 8/20/12 4:08 PM:liquibase: ChangeSet com/cadence/mdv/ngv/initial-changelog.xml::1345376497537-12::pavelber (generated) ran successfully in 54ms
  17. .....
The first changeset (
  •        
  •    
  • The same changelog is working well while running from command line, so I suppose that the problem is in transaction definitions or something like this.


    How to solve this problem?


    Thank you