5 Replies Latest reply on Jan 17, 2008 6:59 AM by Mikhail Balshunou

    ant and schema export

    Mikhail Balshunou Newbie

      Hi all,

      I want to drop and recreate DB schema before running tests to get rid of possible garbage in DB. So I did next thing:

      <hibernatetool destdir="${build.dir}">
       <classpath path="${ejb.build.dir}"/>
       <jpaconfiguration persistenceunit="pmpak"/> <!-- Use META-INF/persistence.xml -->
       <hbm2ddl
       drop="true"
       create="true"
       export="true"
       outputfilename="${build.dir}/export-ddl.sql"
       delimiter=";"
       format="true"/>
       </hibernatetool>
      

      It works fine and generates ddl file, but fails to export it into DB. Stack trace is:
      FATAL [main] (DatasourceConnectionProvider.java:55) - Could not find datasource: java:/pmpakDatasource
      [hibernatetool] javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
      [hibernatetool] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
      [hibernatetool] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
      [hibernatetool] at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
      [hibernatetool] at javax.naming.InitialContext.lookup(InitialContext.java:351)
      [hibernatetool] at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
      [hibernatetool] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
      [hibernatetool] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
      [hibernatetool] at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:27)
      [hibernatetool] at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
      [hibernatetool] at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
      [hibernatetool] at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:55)
      [hibernatetool] at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
      [hibernatetool] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
      [hibernatetool] at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
      [hibernatetool] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      [hibernatetool] at java.lang.reflect.Method.invoke(Method.java:585)
      [hibernatetool] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
      [hibernatetool] at org.apache.tools.ant.Task.perform(Task.java:348)
      [hibernatetool] at org.apache.tools.ant.Target.execute(Target.java:357)
      [hibernatetool] at org.apache.tools.ant.Target.performTasks(Target.java:385)
      [hibernatetool] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
      [hibernatetool] at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
      [hibernatetool] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
      [hibernatetool] at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
      [hibernatetool] at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
      [hibernatetool] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
      [hibernatetool] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
      [hibernatetool] ERROR [main] (SchemaExport.java:202) - schema export unsuccessful
      [hibernatetool] org.hibernate.HibernateException: Could not find datasource
      [hibernatetool] at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
      [hibernatetool] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
      [hibernatetool] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
      [hibernatetool] at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:27)
      [hibernatetool] at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
      [hibernatetool] at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
      [hibernatetool] at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:55)
      [hibernatetool] at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
      [hibernatetool] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
      [hibernatetool] at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
      [hibernatetool] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      [hibernatetool] at java.lang.reflect.Method.invoke(Method.java:585)
      [hibernatetool] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
      [hibernatetool] at org.apache.tools.ant.Task.perform(Task.java:348)
      [hibernatetool] at org.apache.tools.ant.Target.execute(Target.java:357)
      [hibernatetool] at org.apache.tools.ant.Target.performTasks(Target.java:385)
      [hibernatetool] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
      [hibernatetool] at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
      [hibernatetool] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
      [hibernatetool] at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
      [hibernatetool] at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
      [hibernatetool] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
      [hibernatetool] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
      [hibernatetool] Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
      [hibernatetool] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
      [hibernatetool] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
      [hibernatetool] at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
      [hibernatetool] at javax.naming.InitialContext.lookup(InitialContext.java:351)
      [hibernatetool] at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
      [hibernatetool] ... 22 more
      [hibernatetool] 1 errors occurred while performing <hbm2ddl>.
      [hibernatetool] Error #1: org.hibernate.HibernateException: Could not find datasource
      


      I suspect it cannot find datasource :) persistence.xml looks like:
      <persistence-unit name="pmpak">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/pmpakDatasource</jta-data-source>
       <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/pmpakEntityManagerFactory"/>
       <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
       </properties>
       </persistence-unit>
      

      and datasource file is
      <datasources>
      
       <local-tx-datasource>
       <jndi-name>pmpakDatasource</jndi-name>
       <connection-url>jdbc:mysql://localhost:3306/pmpak</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>test</user-name>
       <password>test</password>
       </local-tx-datasource>
      
      </datasources>
      


      How can I make it find this datasource? or export ddl into DB in any other way (I would prefer to use datasource though).

      Thanks in advance,
      Mikhail