4 Replies Latest reply on Nov 5, 2012 6:43 AM by Saemmy -

    HibernateException: Dialect class not found in HBM2DDL ant task

    Saemmy - Newbie

      Hi,

       

      I am using <hbm2ddl> ant task for exporting DDL schema. My ant script worked fine for Hibernate 3.6 and Hibernate Tools 3.x.

       

      After upgading to Hibernate 4 and Hibernate Tools 4 I get the following exception:

       

      [hibernatetool] 2012-10-09 15:54:32,327 INFO  [Version.<clinit>(15)] : Hibernate Tools 4.0.0

      [hibernatetool] 2012-10-09 15:54:32,390 WARN  [ConnectionProviderInitiator.initiateService(143)] : HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections

      [hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)

      [hibernatetool] To get the full stack trace run ant with -verbose

      [hibernatetool] org.hibernate.HibernateException: Dialect class not found: com.mycompany.myproduct.integration.dao.hibernate.Oracle10nDialect

      [hibernatetool] org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [com.mycompany.myproduct.integration.dao.hibernate.Oracle10nDialect]

      [hibernatetool] java.lang.ClassNotFoundException: Could not load requested class : com.mycompany.myproduct.integration.dao.hibernate.Oracle10nDialect

      [hibernatetool] A class were not found in the classpath of the Ant task.

      [hibernatetool] Ensure that the classpath contains the classes needed for Hibernate and your code are in the classpath.

       

      BUILD FAILED

      C:\Projekte\MyProduct\workspace-sts-trunk\MyProductWeb-dev\build.xml:143: org.hibernate.HibernateException: Dialect class not found: com.mycompany.myproduct.integration.dao.hibernate.Oracle10nDialect

          at org.hibernate.tool.ant.HibernateToolTask.reportException(HibernateToolTask.java:226)

          at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:189)

          at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)

          at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

          at java.lang.reflect.Method.invoke(Method.java:597)

          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)

      Caused by: org.hibernate.HibernateException: Dialect class not found: com.mycompany.myproduct.integration.dao.hibernate.Oracle10nDialect

          at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:76)

          at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:64)

          at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:174)

          at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)

          at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)

          at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)

          at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:113)

          at org.hibernate.tool.hbm2x.Hbm2DDLExporter.doStart(Hbm2DDLExporter.java:164)

          at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java:95)

          at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:40)

          at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)

          ... 15 more

      Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [com.mycompany.myproduct.integration.dao.hibernate.Oracle10nDialect]

          at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141)

          at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:73)

          ... 25 more

      Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.mycompany.myproduct.integration.dao.hibernate.Oracle10nDialect

          at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

          at java.lang.Class.forName0(Native Method)

          at java.lang.Class.forName(Class.java:247)

          at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)

          ... 26 more

       

      Here is the part of my ant script:

       

      <target name="schemaexport" depends="clean, compile">

              <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="build.classpath" />

              <mkdir dir="${target.dir}/sql"/>

             

              <hibernatetool destdir="${target.dir}/sql">

                  <classpath>

                      <path location="${build.dir}"/>

                  </classpath>

                  <configuration configurationfile="${build.dir}/hibernate.cfg.xml"/>

                  <hbm2ddl

                      export="false"

                      drop="true"

                      outputfilename="DB-create.sql"

                      delimiter=";"

                      format="true"

                  />

              </hibernatetool>

          </target>

       

      The build.dir includes all class files, including the Oracle 10 dialect.

      Did something change in the configuration of hbm2dll in Hibernate Tools 4? Or is this a bug in Hibernate Tools 4?

        • 1. Re: HibernateException: Dialect class not found in HBM2DDL ant task
          Max Rydahl Andersen Master

          does things work if you use the Oracle dialect bundled with Hibernate 4 ?

          • 2. Re: HibernateException: Dialect class not found in HBM2DDL ant task
            Saemmy - Newbie

            Yes, works fine with org.hibernate.dialect.Oracle10gDialect:

             

            [hibernatetool] 2012-10-10 10:08:23,250 INFO  [Version.<clinit>(15)] : Hibernate Tools 4.0.0

            [hibernatetool] 2012-10-10 10:08:23,328 WARN  [ConnectionProviderInitiator.initiateService(143)] : HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections

            [hibernatetool] 2012-10-10 10:08:23,421 INFO  [Dialect.<init>(122)] : HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect

            [hibernatetool] 2012-10-10 10:08:23,437 INFO  [LobCreatorBuilder.useContextualLobCreation(85)] : HHH000422: Disabling contextual LOB creation as connection was null

            [hibernatetool] 2012-10-10 10:08:23,640 INFO  [SchemaExport.execute(343)] : HHH000227: Running hbm2ddl schema export

             

            But with my own dialect, schema exports throws exception. The hibernate.cfg.xml and all my mapping files could be read, but not the dialect. And both are on classpath:

             

            [hibernatetool] Executing Hibernate Tool with a Standard Configuration

            [hibernatetool] 1. task: hbm2ddl (Generates database schema)

            [hibernatetool] 2012-10-10 10:11:16,421 INFO  [Version.<clinit>(37)] : HCANN000001: Hibernate Commons Annotations {4.0.1.Final}

            [hibernatetool] 2012-10-10 10:11:16,453 INFO  [Version.logVersion(41)] : HHH000412: Hibernate Core {4.1.4.Final}

            [hibernatetool] 2012-10-10 10:11:16,468 INFO  [Environment.<clinit>(239)] : HHH000206: hibernate.properties not found

            [hibernatetool] 2012-10-10 10:11:16,468 INFO  [Environment.buildBytecodeProvider(342)] : HHH000021: Bytecode provider name : javassist

            [hibernatetool] 2012-10-10 10:11:16,515 INFO  [Configuration.configure(1985)] : HHH000042: Configuring from file: hibernate.cfg.xml

            [hibernatetool] 2012-10-10 10:11:16,656 INFO  [Configuration.addResource(718)] : HHH000221: Reading mappings from resource: com/mycompany/myproduct/common/model/hbm/BusinessDivision.hbm.xml

            [hibernatetool] 2012-10-10 10:11:17,000 INFO  [Configuration.addResource(718)] : HHH000221: Reading mappings from resource: com/mycompany/myproduct/common/model/hbm/CommodityCode.hbm.xml

            [hibernatetool] 2012-10-10 10:11:17,015 INFO  [Configuration.addResource(718)] : HHH000221: Reading mappings from resource: com/mycompany/myproduct/common/model/hbm/CompanyCode.hbm.xml

            [hibernatetool] 2012-10-10 10:11:17,062 INFO  [Configuration.addResource(718)] : HHH000221: Reading mappings from resource: com/mycompany/myproduct/common/model/hbm/Country.hbm.xml

            [hibernatetool] 2012-10-10 10:11:17,171 INFO  [Configuration.addResource(718)] : HHH000221: Reading mappings from resource: com/mycompany/myproduct/common/model/hbm/Customer.hbm.xml

            ...

            [hibernatetool] 2012-10-10 10:11:17,750 INFO  [Configuration.doConfigure(2068)] : HHH000041: Configured SessionFactory: null

            [hibernatetool] 2012-10-10 10:11:18,468 INFO  [Version.<clinit>(15)] : Hibernate Tools 4.0.0

            [hibernatetool] 2012-10-10 10:11:18,546 WARN  [ConnectionProviderInitiator.initiateService(143)] : HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections

            [hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)

            [hibernatetool] To get the full stack trace run ant with -verbose

            [hibernatetool] org.hibernate.HibernateException: Dialect class not found: com.mycompany.myproduct.integration.dao.hibernate.Oracle10nDialect

            [hibernatetool] org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [com.mycompany.myproduct.integration.dao.hibernate.Oracle10nDialect]

            [hibernatetool] java.lang.ClassNotFoundException: Could not load requested class : com.mycompany.myproduct.integration.dao.hibernate.Oracle10nDialect

            [hibernatetool] A class were not found in the classpath of the Ant task.

            [hibernatetool] Ensure that the classpath contains the classes needed for Hibernate and your code are in the classpath.

            • 3. Re: HibernateException: Dialect class not found in HBM2DDL ant task
              Max Rydahl Andersen Master

              if you can create a small testsetup to reproduce this that would be great!

               

              its very weird if it can actually load your user classes referenced in your hbm.xml files but can't load your hibernate dialect...

              • 4. Re: HibernateException: Dialect class not found in HBM2DDL ant task
                Saemmy - Newbie

                Hi Max,

                 

                OK, now I have prepared a test case. Please find it in the attached ZIP file. It´s an Eclipse project with Ant task. You will find the exception, if you run the Ant task.

                 

                I think, it´s a bug in the HBM2DLL ant task.

                 

                Best regards

                Sam