Cannot get diff against Hibernate to work in ant

You just need to make sure that the Oracle JDBC driver jar is included in your list of jars. I am not sure what is in liquibase-oracle-3.0.0.jar, but it seems like that is the problem.

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

I am using these jars:
hibernate-core-4.2.7.SP1-redhat-3.jar
liquibase.jar (3.4.2)
liquibase-hibernate4.2-3.5.jar
liquibase-oracle-3.0.0.jar

As well as the other required jars of course.

My database:
    <liquibase:database id=“my-database”
        driver="${liquibase.database.driver}"
        url="${liquibase.database.url}"
        user="${liquibase.database.username}"
        password="${liquibase.database.password}" >
    </liquibase:database>

liquibase.properties:
liquibase.database.username=emr
liquibase.database.password=xxxx
liquibase.database.driver=oracle.jdbc.driver.OracleDriver
liquibase.database.url=jdbc:oracle:thin:@(xxxx)
liquibase.persistence.unit=hibernate:ejb3:emrEJB?dialect=org.hibernate.dialect.OracleDialect

My ant diff target:
   
        <liquibase:diffDatabaseToChangeLog
                databaseref=“my-database”
                classpathref=“mypath.classpath”
                diffTypes=“tables,columns,views”>
           
           
        </liquibase:diffDatabaseToChangeLog>
   

I’ve tried a lot of different variations of the ant target and even tried the latest snapshot jar of liquibase.  But every time I run I get the same error:
BUILD FAILED
C:\Production\jboss_emr_eap\g2\dbautomation.xml:111: JDBC driver is required.

Does the hibernate extension actually work with the latest liquibase jar?  I swear I had this working in a previous version of liquibase but I seem to have misplaced that code.

If I run ant with the debug flag I get the full stack trace.  (BTW I’m running ant inside eclipse):

    at liquibase.integration.ant.type.DatabaseType.validateParameters(DatabaseType.java:133)
    at liquibase.integration.ant.type.DatabaseType.createDatabase(DatabaseType.java:51)
    at liquibase.integration.ant.BaseLiquibaseTask.createDatabaseFromType(BaseLiquibaseTask.java:100)
    at liquibase.integration.ant.AbstractDatabaseDiffTask.getDiffResult(AbstractDatabaseDiffTask.java:24)
    at liquibase.integration.ant.DiffDatabaseToChangeLogTask.executeWithLiquibaseClassloader(DiffDatabaseToChangeLogTask.java:44)
    at liquibase.integration.ant.BaseLiquibaseTask.execute(BaseLiquibaseTask.java:81)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:392)
    at org.apache.tools.ant.Target.performTasks(Target.java:413)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)

Thanks for the suggestion.  I should have mentioned that I am including ojdbc6.jar, which does include the Oracle driver.  I also removed liquibase-oracle-3.0.0.jar, but still the same error.

I looked at the source code for the line mentioned in the stack trace.  It asks for the driver.  Since this is a diff operation I’m not sure if the missing driver is for Oracle or for Hibernate.  I was assuming the error was about Hibernate since I am supplying a driver for Oracle.  But perhaps for some reason it doesn’t see that variable.

Perhaps someone could post a complete working example of the ant script and properties required to get this to work.  I’ve tried dozens of variations of jar files, properties, and attributes for the diffDatabaseToChangeLog task.  But I always get exactly the same error about the JDBC driver being required.

Your element is not fully filled out. That element is the same type as a element and takes the same attributes. Something like this:


        <liquibase:diffDatabaseToChangeLog
                databaseref=“my-database”
                classpathref=“mypath.classpath”
                diffTypes=“tables,columns,views”>
           
           
        </liquibase:diffDatabaseToChangeLog>
   

See if that helps.

Thanks.  That gets past the JDBC driver issue but now I have this:

diff-against-hibernate2:
[liquibase:diffDatabaseToChangeLog] Starting Liquibase.
dropping C:\Production\jboss_emr_eap\g2\buildLibs\hibernate-common-annotations-4.0.1.Final-redhat-2.jar from path as it doesn’t exist
[liquibase:diffDatabaseToChangeLog] WARNING 4/12/16 1:39 PM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateSpringDatabase as a Liquibase service because org.springframework.beans.factory.support.BeanDefinitionRegistry is not in the classpath

BUILD FAILED
C:\Production\jboss_emr_eap\g2\dbautomation.xml:52: Unable to create Liquibase Database instance. Could not connect to the database.
    at liquibase.integration.ant.type.DatabaseType.createDatabase(DatabaseType.java:78)
    at liquibase.integration.ant.BaseLiquibaseTask.createDatabaseFromType(BaseLiquibaseTask.java:96)
    at liquibase.integration.ant.AbstractDatabaseDiffTask.getDiffResult(AbstractDatabaseDiffTask.java:24)
    at liquibase.integration.ant.DiffDatabaseToChangeLogTask.executeWithLiquibaseClassloader(DiffDatabaseToChangeLogTask.java:44)
    at liquibase.integration.ant.BaseLiquibaseTask.execute(BaseLiquibaseTask.java:81)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:392)
    at org.apache.tools.ant.Target.performTasks(Target.java:413)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
    at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)

Thanks.  I changed the jdbc driver for the referencedatabase only to liquibase.ext.hibernate.database.connection.HibernateDriver based on something I read in one of the forum posts here.  So my target looks like this:

        <liquibase:generateChangeLog databaseref=“my-database”
            classpathref=“mypath.classpath” >
            <liquibase:xml outputfile="/path/to/output/changelog.xml" encoding=“UTF-8”/>
        </liquibase:generateChangeLog>
        This works perfectly.

It looks like the Liquibase cannot connect to the database. It is trying to call driver.connect()on the given JDBC URL and driver and that method is returning null. According to the JDBC Javadoc:

The driver should return “null” if it realizes it is the wrong kind of driver to connect to the given URL.

I would double-check your JDBC URL and driver attributes on your and elements and make sure it is correct and pointing to the right place.

I have very limited experience with the hibernate plugin but based on the ClassNotFoundException I would say that the classpath given to the ant task doesn’t have everything it needs to run. The javax.persistence package tells me that it is missing the JPA API/interface jar (I think that is something like persistence-api.jar). You can try to print out the classpath that to see if all the jars you expect are present. You can print out a path with an id like this (Ant >= 1.7).
${toString:mypath.classpath}

Hope this helps.