-->
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.  [ 6 posts ] 
Author Message
 Post subject: hbm2java - cannot find my template
PostPosted: Sun Aug 01, 2004 2:40 pm 
Newbie

Joined: Tue Jul 27, 2004 1:33 pm
Posts: 18
Location: South Africa
I am trying to use the velocity generator in the hbm2java tool. I cannot get the ant task to find the template. I have get the following error

Code:
[hbm2java] org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'pojomxc.vm'


This is the ant task. Its weird the hbm.xml files are located ok. But not the template. I am a newbie at ant so maybe I am declaring that wrong?

Code:
<target name="hbm2java"
   description="Generate .java from .hbm files.">
      <property name="hbm.dir" location="${hibernate.poj.src.dir}"/>
      <taskdef
         name="hbm2java"
         classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
         classpathref="hibernate.classpath"
      />
      <hbm2java output="${src.dir}" classpathref="hibernate.classpath" config="src/config.xml">
         <fileset dir="${build.gen-src.dir}/">
            <include name="**/*.hbm.xml"/>
         </fileset>
         <fileset file="${build.gen-src.dir}/pojomxc.vm" />
      </hbm2java>
   </target>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 01, 2004 5:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the .vm file has to be in the classpath - you are adding it as a argument which is not correct.

Btw. may I ask why you are using velocity instead of the basic renderer ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 5:51 am 
Newbie

Joined: Tue Jul 27, 2004 1:33 pm
Posts: 18
Location: South Africa
Hi Max,

I want to customise the output of the code generator. According to my understanding I can do quite a lot of customisation to the code produced with the velocity template.

I want to produce two sets of object. The basic value objects and then a "concrete" class which I can use to decorate the value objects with extra functionality. For example I would like the objects to implement an interface with the following signature

public Object getNaturalKey();
public int getPrimaryKey();

The natural key will be used to sort collections of the object with the comparable interface. Also I use a lot of JTables to display the objects. Getting meta-information such as column names, column classes, number of fields etc requires a lot of repetitive coding. I was hoping to use the template to produce this for me and then just use a generic tablemodel to request this info from the wrapped value objects.

Maybe this should be done with another velocity proggie but you already have all the info I need in the context used by the hbm2java tool.

Let me know if there is a better approach.

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 8:24 am 
Newbie

Joined: Tue Jul 27, 2004 1:33 pm
Posts: 18
Location: South Africa
Ok so I have done the following in the build.xml. As can be seen I have included the vm file in the classpath. I have copied it to the project.lib directory. (I know that this is not a hibernate-tool error. I just don't understand how to use ant properly I suppose.)

Code:
<path id="hibernate.classpath">
   <fileset dir="${hibernate.hdb2java}">
      <include name="**/*.jar"/>
   </fileset>
   <fileset dir="${project.lib}">
      <include name="**/*.jar"/>
      <include name="**/*.vm"/>
   </fileset>
</path>



When I run the build script now I get a lot more error. These may relate to the fact that I am passing incorrect value in via the config.xml file.

Sorry the output below is long. Essentially though it starts to complain about unzipping errors, which I assume is the pojomxc.vm file as all the other files in the lib directory are jar files. At the end of the pasted output, but not the entire error you can see it still complains about not finding the template.

Code:
[hbm2java] Building hibernate objects
[hbm2java] java.util.zip.ZipException: error in opening zip file
[hbm2java] at java.util.zip.ZipFile.open(Native Method)
[hbm2java] at java.util.zip.ZipFile.<init>(ZipFile.java:112)
[hbm2java] at java.util.zip.ZipFile.<init>(ZipFile.java:128)
[hbm2java] at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:903)
[hbm2java] at org.apache.tools.ant.AntClassLoader.getResource(AntClassLoader.java:832)
[hbm2java] at org.apache.log4j.helpers.Loader.getResource(Loader.java:91)
[hbm2java] at org.apache.log4j.LogManager.<clinit>(LogManager.java:94)
[hbm2java] at org.apache.log4j.Logger.getLogger(Logger.java:85)
[hbm2java] at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:229)
[hbm2java] at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:65)
[hbm2java] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[hbm2java] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
[hbm2java] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
[hbm2java] at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
[hbm2java] at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
[hbm2java] at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
[hbm2java] at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
[hbm2java] at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
[hbm2java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.<clinit>(CodeGenerator.java:32)
[hbm2java] at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(Hbm2JavaTask.java:145)
[hbm2java] at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.execute(Hbm2JavaTask.java:95)
[hbm2java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269)
[hbm2java] at org.apache.tools.ant.Task.perform(Task.java:364)
[hbm2java] at org.apache.tools.ant.Target.execute(Target.java:301)
[hbm2java] at org.apache.tools.ant.Target.performTasks(Target.java:328)
[hbm2java] at org.apache.tools.ant.Project.executeTarget(Project.java:1215)
[hbm2java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:379)
[hbm2java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:135)
[hbm2java] java.util.zip.ZipException: error in opening zip file
[hbm2java] at java.util.zip.ZipFile.open(Native Method)
[hbm2java] at java.util.zip.ZipFile.<init>(ZipFile.java:112)
[hbm2java] at java.util.zip.ZipFile.<init>(ZipFile.java:128)
[hbm2java] at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:903)
[hbm2java] at org.apache.tools.ant.AntClassLoader.getResource(AntClassLoader.java:832)
[hbm2java] at org.apache.log4j.helpers.Loader.getResource(Loader.java:91)
[hbm2java] at org.apache.log4j.LogManager.<clinit>(LogManager.java:96)
[hbm2java] at org.apache.log4j.Logger.getLogger(Logger.java:85)
[hbm2java] at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:229)
[hbm2java] at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:65)
[hbm2java] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[hbm2java] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
[hbm2java] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
[hbm2java] at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
[hbm2java] at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
[hbm2java] at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
[hbm2java] at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
[hbm2java] at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
[hbm2java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.<clinit>(CodeGenerator.java:32)
[hbm2java] at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(Hbm2JavaTask.java:145)
[hbm2java] at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.execute(Hbm2JavaTask.java:95)
[hbm2java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269)
[hbm2java] at org.apache.tools.ant.Task.perform(Task.java:364)
[hbm2java] at org.apache.tools.ant.Target.execute(Target.java:301)
[hbm2java] at org.apache.tools.ant.Target.performTasks(Target.java:328)
[hbm2java] at org.apache.tools.ant.Project.executeTarget(Project.java:1215)
[hbm2java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:379)
[hbm2java] at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:135)
[hbm2java] log4j:WARN No appenders could be found for logger (net.sf.hibernate.util.DTDEntityResolver).
[hbm2java] log4j:WARN Please initialize the log4j system properly.
[hbm2java] org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'pojomxc.vm'
[hbm2java] at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:501)


For good measure here is the config.xml file

Code:
<codegen>
              <generate prefix="Base" renderer="net.sf.hibernate.tool.hbm2java.BasicRenderer"/>
            <generate renderer="net.sf.hibernate.tool.hbm2java.VelocityRenderer">
                 <param name="template">pojomxc.vm</param>
                <param name="generate-empty-concrete-classes">true</param>
              </generate>
</codegen>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 8:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it has to be IN the classpath not BE the classpath.

Meaning you should list either the folder it is placed in or add it to a .zip or .jar file.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 2:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
mxc4 wrote:
Hi Max,

I want to customise the output of the code generator. According to my understanding I can do quite a lot of customisation to the code produced with the velocity template.


Yes - that is true, but I personally prefer the basic generation code as it is much more feature complete - and produces much better readable code than the velocity macros (IMHO)

mxc4 wrote:
I want to produce two sets of object. The basic value objects and then a "concrete" class which I can use to decorate the value objects with extra functionality. For example I would like the objects to implement an interface with the following signature


You do now that hbm2java support this natively with the generated-class attribute ? (and the more new "generate-concrete-empty-classes")

Quote:
public Object getNaturalKey();
public int getPrimaryKey();

The natural key will be used to sort collections of the object with the comparable interface. Also I use a lot of JTables to display the objects. Getting meta-information such as column names, column classes, number of fields etc requires a lot of repetitive coding. I was hoping to use the template to produce this for me and then just use a generic tablemodel to request this info from the wrapped value objects.



hmm - why not use normal reflection for that ?

Oh well - if I were you I would try to simply extend the BasicRenderer and add a generateNaturalAndPrimaryKey() method to it - much easier in my world - and you get the full benefits of hbm2java instead of relying on the much weaker velocity based version. (but that is just me ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.