Hibernate annotations

Hi,

I would like to use hibernate annotations with liquibase and I thought I was successfull. But I only could create the initial changelog.xml

Sadly it seems to me that liquibase 1.9.* does not support annotations. Is this right? As a workaround I can think of a database created from hibernate’s SchemaExport and then do a diff to the life-database. Does anyone has experiences with this? Or how do you handle hibernate + liquibase?

I also read that 2.1 will support hibernate-diff via annotations.
Is http://liquibase.jira.com/source/browse/CONTRIB/trunk/hibernate the correct place in the source?

Regards,
Peter.

related links:
http://liquibase.org/forum/index.php?topic=75.0

http://liquibase.org/forum/index.php?topic=43.0

http://liquibase.jira.com/browse/CORE-395

http://liquibase.org/forum/index.php?topic=213.0

You are right that the 2.0+ codebase for hibernate is at http://liquibase.jira.com/source/browse/CONTRIB/trunk/hibernate.  I was working on it a bit last night to make sure it was working with trunk.

I haven’t tried to get it to work with annotations, but it may not be difficult.  I’ll take a quick look.

Nathan

Thanks Nathan!

There are a lot of tests failing in liquibase core. Is this okay?

And I got the hibernate integration working via the workaround of a separate migration database (created from SchemaExport) and then diffing with my current database:

#1. execute the following

    Configuration config = getConfiguration(); config.setProperty("hibernate.connection.url", "jdbc:h2:~/.myapp/migrate-db"). SchemaExport schemaTool = new SchemaExport(config); schemaTool.drop(false, true); schemaTool.create(false, true);

#2. then create the change log

    liquibase --driver=org.h2.Driver \           --url=jdbc:h2:~/.myapp/migrate-db \           --username=sa --password=tmp \           --changeLogFile=src/main/resources/dbchangelog.xml \       diffChangeLog \           --baseUrl=jdbc:h2:~/.myapp/test-db --baseUsername=sa --basePassword=tmp

This works except that I have to change some addForeignKeyConstraint:s.
E.g. 4 constraints are created at once, but 2 of them use the wrong basetable! Is this a liquibase bug? I was using liquibase 1.9.5 for that test.

I fixed trunk so there should be no failing tests now.  There were a couple in the integration tests module.  Were you getting some in core too?  If so, which ones?

Good you have a work around, but the goal would be to not have to do that.

Nathan

  1. my mistake: there are failures in the integration tests

  2. To bring the conversation to only one medium, here is my email respones (sorry for the confusion):

I did not have sth. like in my hibernate.cfg.xml. Could this be the problem?

Instead I am using

AnnotationConfiguration annoCfg = new AnnotationConfiguration();
for (Class<?> c : mappedClasses) {
  annoCfg = annoCfg.addAnnotatedClass(c);
}

It is working for me with annotations using the 2.0 codebase.

Would you give me the ant task or cmd line parameters for this?

and when I run thie diffChangeLog against it, I get createTable statements.

I get them too. But only if baseUrl=hibernate which is wrong, right? I think it should be the otherway around (baseUrl=database; url=hibernate). Because every additional changes does not result in further changes of the changelog.xml

Regards,
Peter.