How to integrate LiquiBase + Spring + Hibernate without using the hibernate.xml configuration file

I already read a lot of integration messages between LiquiBase, Spring, and Hibernate, but none of them apply to my situation:

I am starting a new project that uses Spring and Hibernate, so I was looking for a way to manage database changes throughout the project life cycle. At first I started using hbm2ddl, but then I realized that people say that this is not a good idea in production environments, so I came to the conclusion that LiquiBase is the way to go (so I think).

The problem is that I do not use the hibernate.xml configuration file (and all the examples I found using LiquiBase use hibernate.xml), since I use java annotations in my POJO / DB classes and in my sleep mode, the configuration is as follows

@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() throws ClassNotFoundException { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource()); entityManagerFactoryBean.setPackagesToScan(environment.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN)); entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistence.class); Properties jpaProterties = new Properties(); jpaProterties.put(PROPERTY_NAME_HIBERNATE_DIALECT, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_DIALECT)); jpaProterties.put(PROPERTY_NAME_HIBERNATE_FORMAT_SQL, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_FORMAT_SQL)); jpaProterties.put(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY)); jpaProterties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL)); jpaProterties.put(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO)); entityManagerFactoryBean.setJpaProperties(jpaProterties); return entityManagerFactoryBean; } 

I also found posts from 2 years ago saying that this option will only be available in version 2.0 (current), and I was wondering if this has already been implemented. If so, how can I use it in an ANT script?

I need to create the original DDL database and the following database change logs and import them into the production database.

EDIT: I use:

Liquibase 2.0.5

Liquibase Hibernate 2.0.0

Sleep 4.1.4

Spring 3.1.1

Spring JPA 1.1.1 Data

+8
spring annotations hibernate ant liquibase
source share
1 answer

Have you looked at http://www.liquibase.org/documentation/spring.html ?

It mentions dataSource and hibernate.xml.

For initial generation, you can use command line mode and generateChangeLog .

See http://www.liquibase.org/documentation/command_line.html .

Here is the minimal hibernate.xfg.xml you will need:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory name="entityManagerFactoryBean"> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3307/test</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">123456</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> </session-factory> </hibernate-configuration> 
+3
source share

All Articles