liquibase is a perfect alternative to hibernate's hbm2ddl_auto property if you are using xml-mapping. But Im using JPA annotation (hibernate annotations). Is it possible to use liquibase then?
Asked
Active
Viewed 1.7k times
36
-
2Did you get this working with the annotations? The Liquibase documentation page referenced below only covers pointing it to an XML file. – Dave Oct 06 '10 at 21:17
-
1Nathan Voxland created a patched release for me – Schildmeijer Oct 07 '10 at 06:12
1 Answers
24
Yes, Liquibase uses hibernate's metadata classes, which are the same whether you use xml mappings or annotations. You do need a hibernate config file to point liquibase to, but your mappings can be xml or jpa annotations. More information can be found at https://github.com/liquibase/liquibase-hibernate/wiki but you can use "database urls" such as
hibernate:classic:com/example/hibernate.cfg.xml
if you have a hibernate xml conf file or
hibernate:ejb3:myPersistenceUnit
if you have a META-INF/persistence.xml, or
hibernate:spring:com.example?dialect=org.hibernate.dialect.MySQL5Dialect
if you would like auto-generate a JPA configuration based on a java package containing annotated Entities.

Nathan Voxland
- 15,453
- 2
- 48
- 64
-
1Could you explain a little bit more detailed, or point me to a url – Schildmeijer Jun 17 '09 at 10:07
-
1The liquibase hibernate documentation is at http://www.liquibase.org/manual/hibernate. Is there anything in particular you are wondering? – Nathan Voxland Aug 03 '09 at 05:45
-
1The source should build fine. Send me an email nathan [at] voxland.net and I can help you out – Nathan Voxland Nov 18 '09 at 07:13
-
3The answer is still incomplete. What are the arguments when you don't have a `hibernate.cfg.xml` file? – Otto Allmendinger Nov 16 '11 at 10:21
-
@OttoAllmendinger Yes, exactly. In out case we don have `hibernate.cfg.xml` file. Can we still use LiquiBase? – Piotr Sobczyk Apr 25 '12 at 08:49
-
1Currently if you don't have a hibernate.cfg.xml file, liquibase does not know how to read in your current mappings to compare it to the database schema, so you can't use liquibase to automatically generate changeSets based on your hibernate model. You can still definitely use liquibase still, however, by simply manually appending the changes you need to your changeLog. That is normally the approach I would recommend anyway over a diff-based workflow. – Nathan Voxland Apr 25 '12 at 14:47
-
1@NathanVoxland, Currently we don't have `hibernate.cfg.xml` which are migrated to Spring Java bean configuration. You've mentioned that hibernate.cfg.xml is needed in your previous answer.. But it's been 4 years since that, So is `hibernate.cfg.xml` still needed if I'm gng to use liquibase (latest version) for schema generation / diff based on Hibernate annotated model classes in a package..? – The Coder Mar 28 '16 at 09:43