# Hibernate annotations

**URL:** https://forum.liquibase.org/t/hibernate-annotations/602
**Category:** General Discussion
**Created:** [July 10, 2010, 1:07pm UTC](https://forum.liquibase.org/t/hibernate-annotations/602 "2010-07-10T13:07:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![peathal](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@peathal](https://forum.liquibase.org/u/peathal)
#### Post date: [July 10, 2010, 1:07pm UTC](https://forum.liquibase.org/t/hibernate-annotations/602/1 "2010-07-10T13:07:00Z")

</div>

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](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=75.0)

[http://liquibase.org/forum/index.php?topic=43.0](http://liquibase.org/forum/index.php?topic=43.0)

[http://liquibase.jira.com/browse/CORE-395](http://liquibase.jira.com/browse/CORE-395)

[http://liquibase.org/forum/index.php?topic=213.0](http://liquibase.org/forum/index.php?topic=213.0)

---

<div class="post-metadata">

### Author: ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)
#### Post date: [July 10, 2010, 1:07pm UTC](https://forum.liquibase.org/t/hibernate-annotations/602/2 "2010-07-10T13:07:00Z")

</div>

You are right that the 2.0+ codebase for hibernate is at [http://liquibase.jira.com/source/browse/CONTRIB/trunk/hibernate.&nbsp;](http://liquibase.jira.com/source/browse/CONTRIB/trunk/hibernate.%C2%A0) 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.&nbsp; I’ll take a quick look.

Nathan

---

<div class="post-metadata">

### Author: ![peathal](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@peathal](https://forum.liquibase.org/u/peathal)
#### Post date: [July 10, 2010, 1:07pm UTC](https://forum.liquibase.org/t/hibernate-annotations/602/3 "2010-07-10T13:07:00Z")

</div>

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 \ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --url=jdbc:h2:~/.myapp/migrate-db \ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --username=sa --password=tmp \ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --changeLogFile=src/main/resources/dbchangelog.xml \ &nbsp; &nbsp; &nbsp; diffChangeLog \ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --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.

---

<div class="post-metadata">

### Author: ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)
#### Post date: [July 10, 2010, 1:07pm UTC](https://forum.liquibase.org/t/hibernate-annotations/602/4 "2010-07-10T13:07:00Z")

</div>

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

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

Nathan

---

<div class="post-metadata">

### Author: ![peathal](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@peathal](https://forum.liquibase.org/u/peathal)
#### Post date: [July 10, 2010, 1:07pm UTC](https://forum.liquibase.org/t/hibernate-annotations/602/5 "2010-07-10T13:07:00Z")

</div>

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) {  
&nbsp; 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.
