These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: [Solved] Classpath protocol broken for hibernatetool task
PostPosted: Fri Dec 28, 2007 12:07 pm 
Newbie

Joined: Fri Jul 20, 2007 4:32 am
Posts: 4
I'm running hbm2ddl via the hibernatetool Ant task. I appear to be running into this issue http://forum.hibernate.org/viewtopic.php?t=927396&highlight=entityresolver, namely that the EntityResolver is not able to handle the "classpath://" protocol.

As far as I can makeout, this issue has been fixed. I can see the fix in the source code. I am using the binary for Tools, but the code in the repository for the RC1 looks like it is setting the entity resolver.

I am using the latest HibernateTool (3.2.0.GA) jars. I have also tried explicitly setting the "entityresolver" attribute of annotationconfiguration (as shown below).

Can anyone help? Has anyone else been able to use this ant task with the "classpath://" protocol?

Richard

Hibernate Tools version:
Hibernate 3.2.0.GA

Ant script
Code:
...

<path id="hibernate-tools-lib">
      <path location="${hibernatetools.lib.dir}/hibernate-tools.jar" />
      <path location="${hibernatetools.lib.dir}/hibernate3.jar" />            
      <path location="${hibernatetools.lib.dir}/freemarker.jar" />
      <path location="${lib}/postgresql-8.2.505.jdbc4.jar" />
      <path location="${hibernatetools.lib.dir}/hibernate-annotations.jar" />
      <path location="${hibernatetools.lib.dir}/hibernate-commons-annotations.jar" />
      <path location="${hibernatetools.lib.dir}/dom4j-1.6.1.jar" />
      
   </path>

...

<target name="export-schema"
         description="Generates a database create script">
   
      <hibernatetool destdir="${database.scripts}">
      
         <classpath>
            <pathelement location="${jar.dir}" />
            <pathelement location="${lib.dir}/mvanamibia-dim.jar" />
            <pathelement location="${lib.dir}/joda-time-1.4.jar" />
         </classpath>
      
         <annotationconfiguration
            configurationfile="${basedir}/resources/hibernate/hibernate.cfg.xml"
            entityresolver="org.hibernate.util.DTDEntityResolver" />
            
         <hbm2ddl
            drop="false"
            export="false"
            create="true"
            outputfilename="create_schema.ddl"            
            format="true" />
      
      </hibernatetool>
   
   </target>
...

Mapping documents:
Code:
<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
   [
   <!ENTITY mappings SYSTEM "classpath://mappings.cfg.xml">
   <!ENTITY auxiliary SYSTEM "classpath://auxiliary.hbm.xml">
   ]>

<hibernate-configuration>

   <session-factory name="java:/mvanamibia3SessionFactory">      

      <property name="show_sql">true</property>
      <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
      <!--
      <property name="hibernate.hbm2ddl.auto">create-drop</property>
      -->
      <property name="connection.datasource">java:/mvanamibia3</property>      
      <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
      <property name="transaction.flush_before_completion">true</property>
      <property name="connection.release_mode">after_statement</property>
      <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
      <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
      
      &mappings;
      
      &auxiliary;
            
   </session-factory>

</hibernate-configuration>


Full stack trace of any exception that occurs:
Code:
export-schema:
[hibernatetool] Executing Hibernate Tool with a Hibernate Annotation/EJB3 Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] Dec 28, 2007 3:20:35 PM org.hibernate.cfg.annotations.Version <clinit>
[hibernatetool] INFO: Hibernate Annotations 3.3.0.GA
[hibernatetool] Dec 28, 2007 3:20:35 PM org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: Hibernate 3.2.5
[hibernatetool] Dec 28, 2007 3:20:35 PM org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: hibernate.properties not found
[hibernatetool] Dec 28, 2007 3:20:35 PM org.hibernate.cfg.Environment buildBytecodeProvider
[hibernatetool] INFO: Bytecode provider name : cglib
[hibernatetool] Dec 28, 2007 3:20:35 PM org.hibernate.cfg.Environment <clinit>
[hibernatetool] INFO: using JDK 1.4 java.sql.Timestamp handling
Using org.hibernate.util.DTDEntityResolver as entity resolver
[hibernatetool] Dec 28, 2007 3:20:35 PM org.hibernate.cfg.Configuration configure
[hibernatetool] INFO: configuring from file: hibernate.cfg.xml
[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: Could not parse configuration: /home/richard/workspace/mvanamibia3/webapp/resources/hibernate/hibernate.cfg.xml
[hibernatetool] org.dom4j.DocumentException: unknown protocol: classpath Nested exception: unknown protocol: classpath

BUILD FAILED
/home/richard/workspace/mvanamibia3/webapp/build.xml:525: org.hibernate.HibernateException: Could not parse configuration: /home/richard/workspace/mvanamibia3/webapp/resources/hibernate/hibernate.cfg.xml
        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:288)
        at sun.reflect.GeneratedMethodAccessor2.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:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
        at org.apache.tools.ant.Main.runBuild(Main.java:698)
        at org.apache.tools.ant.Main.startAnt(Main.java:199)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: org.hibernate.HibernateException: Could not parse configuration: /home/richard/workspace/mvanamibia3/webapp/resources/hibernate/hibernate.cfg.xml
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1494)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
        at org.hibernate.tool.ant.ConfigurationTask.doConfiguration(ConfigurationTask.java:96)
        at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
        at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:302)
        at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:45)
        at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
        ... 16 more
Caused by: org.dom4j.DocumentException: unknown protocol: classpath Nested exception: unknown protocol: classpath
        at org.dom4j.io.SAXReader.read(SAXReader.java:484)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1484)
        ... 22 more
--- Nested Exception ---
org.hibernate.HibernateException: Could not parse configuration: /home/richard/workspace/mvanamibia3/webapp/resources/hibernate/hibernate.cfg.xml
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1494)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
        at org.hibernate.tool.ant.ConfigurationTask.doConfiguration(ConfigurationTask.java:96)
        at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
        at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:302)
        at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:45)
        at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.GeneratedMethodAccessor2.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:105)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
        at org.apache.tools.ant.Main.runBuild(Main.java:698)
        at org.apache.tools.ant.Main.startAnt(Main.java:199)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: org.dom4j.DocumentException: unknown protocol: classpath Nested exception: unknown protocol: classpath
        at org.dom4j.io.SAXReader.read(SAXReader.java:484)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1484)
        ... 22 more

Total time: 0 seconds


Last edited by thatrichard on Fri Dec 28, 2007 3:11 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 28, 2007 1:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
report it in jira.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 28, 2007 3:10 pm 
Newbie

Joined: Fri Jul 20, 2007 4:32 am
Posts: 4
I've solved this problem. There were two things wrong with my configuration:

Firstly, the first path element 'hibernate' was missing in the entity declaration, which now reads: <!ENTITY mappings SYSTEM classpath://hibernate/mappings.cfg.xml">

Secondly, the parent folder of 'hibernate' ('resources') was not declared in the classpath for the hibernatetool task, which now includes: <pathelement location="${basedir}/resources" />

However, the resulting error message (taken from my original post) couldn't be more misleading:

Code:
org.dom4j.DocumentException: unknown protocol: classpath Nested exception: unknown protocol: classpath


This cost me a lot of time, so I will report this in Jira.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.