I am using both Liquibase
and Hibernate
libraries in my application. They both work with the same database, but each requires it's own properties
file. However, some of the database-specific fields are common. I would like to avoid duplication of those fields and having them in both files. I would like to have those properties in a single file that Liquibase and Hibernate properties file would read from.
Currently I have.
liquibase.properties
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/mydb
username: root
password: root
hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.hbm2ddl.auto">none</property>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/mydb</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
Note how driver, URL, username and password are duplicated in those 2 files. Ideally, I'd have some 3rd file like this.
database.properties
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/mydb
username: root
password: root
And then something like.
liquibase.properties
driver: ${driver}
url: ${url}
username: ${username}
password: ${password}
hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.hbm2ddl.auto">none</property>
<!-- Database connection settings -->
<property name="connection.driver_class">${driver}</property>
<property name="connection.url">${url}</property>
<property name="connection.username">${username}</property>
<property name="connection.password">${password}</property>
Is something like that possible?