-->
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.  [ 5 posts ] 
Author Message
 Post subject: Code Gen: How to specify path to non-hibernate custom types
PostPosted: Tue Nov 22, 2005 5:59 pm 
Beginner
Beginner

Joined: Tue Nov 15, 2005 6:56 pm
Posts: 39
Using Hibernate-tools-Beta1

I'm getting an error trying to generate code from my hbm.xml files using hte HibernateToolTask. I'm running a custom exporter via the hbmtemplate ant task. I'm getting this error:

Code:
[hibernatetool] SEVERE: Method get threw exception for reference $templates in template pojo/Pojo.vm at  [10,1]


The particular hbm.xml file that it's trying to process has custom data types for some of the columns. These datatypes are non-hibernate pojos that are compiled with a different build process. I know these are causing the problem since when I change them to just "string" type, everything seems to work fine. I've tried specifying the path to these pojos in my build file but it still doesn't seem to make a difference. I've tried variations like this: (I've noted places in the build file below where I tried to specify the class path)

Code:
<taskdef
     name="hibernatetool"
     classname="org.hibernate.tool.ant.HibernateToolTask"
     classpath="**Tried specifying path to pojo class files here**[location of hibernate-tools.jar, velocity-1.4.jar, velocity-tools-generic-1.4.jar, jtidy-r8-21122004.jar, hibernate3.jar & jdbc drivers]"/>
      
  <hibernatetool destdir="[output dir]">
   <classpath> <!-- a classpath is optional, but needed for exporters that require access to domain classes etc. -->
    <path location="**tried specifying path to pojo class files here**"/>
   </classpath>
   
   <configuration configurationfile="hibernate.cfg.xml" >
    <fileset dir="${src.dir}/../test" id="id"> <!-- A configuration can take a configurationfile and/or a fileset of hbm.xml's -->
      <include name="**/*TopDown.hbm.xml"/>
    </fileset>
   </configuration>

<hbmtemplate template="pojo.vm" exporterclass="MyPOJOExporter" filepattern="{package-name}/{class-name}"/>
            
  </hibernatetool>


I can't seem to get it work. Any help is appreciated.


Top
 Profile  
 
 Post subject: Additional Information to help debug this...
PostPosted: Tue Nov 22, 2005 9:11 pm 
Beginner
Beginner

Joined: Tue Nov 15, 2005 6:56 pm
Posts: 39
Here is some additional information that may help anyone that is looking at this.

I looked at the calls being made as the custom exporter is being run and noticed that the exception is thrown in Cfg2JavaTool.java class in this method:

Code:
private String getJavaTypeName(Value value, boolean preferRawTypeNames)


Specifically, when this line of code is run:

Code:
return toName( type.getReturnedClass() );


I wrote some debug code and found that type.getName() returns the right name for my class. It's just the type.getReturnedClass() call that throws an exception.

Any Ideas. Remember, the type here is a custom type that is not a hibernate pojo. It's a class compiled outside of the hibernate world.

Thanks,
Sam


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 8:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
user custom types should just work.

could you reduce it down to a simple test and put it in jira then i'll look at it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 10:25 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Hi,

we got this to work using something like:

Code:
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask">
   <classpath refid="hibernatetool.class.path" />
</taskdef>


where hibernatetool.class.path contains the custom user types
and can be defined like:

Code:
  <path id="hibernatetool.class.path">
     <pathelement location="${hibernate.lib.dir}/tools/hibernate-tools.jar"/>
     <pathelement location="${hibernate.lib.dir}/tools/velocity-1.4.jar"/>
     <pathelement location="${hibernate.lib.dir}/tools/velocity-tools-generic-1.1.jar"/>
     <pathelement location="${hibernate.lib.dir}/tools/jtidy-r8-21122004.jar"/>
     <pathelement location="${hibernate.lib.dir}/hibernate3.jar"/>
     <pathelement location="${workspace.dir}/Base/lib/db2java.zip"/>
     <path refid="IfbHibernate.class.path"/>
      <pathelement location="${IfbHibernate.dir}/bin"/>
  </path>


This is really difficult to debug, like all classpath problems.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 8:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it should also work by just having the classes in the <hibernatetool> classpath - if not, open a jira issue with a simple failing example.

_________________
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.  [ 5 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.