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.  [ 24 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: <hbm2dao> ... getJavaTypeName() error
PostPosted: Thu Aug 10, 2006 3:21 am 
Beginner
Beginner

Joined: Wed Aug 09, 2006 11:26 am
Posts: 20
Hi everybody,

I use the following target to generate daos:

<target name="hbm2dao">
<hibernatetool destdir="${src}">
<configuration configurationfile="${src}/hibernate.cfg.xml"/>
<hbm2dao/>
</hibernatetool>
</target>

Only a few daos get generated when i get the exception:

hbm2dao:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2dao (Generates a set of DAOs)
[hibernatetool] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[hibernatetool] log4j:WARN Please initialize the log4j system properly.
[hibernatetool] An exception occurred while running exporter #2:hbm2dao (Generates a set of DAOs)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.tool.hbm2x.ExporterException: Error while processing template daohome.ftl
[hibernatetool] freemarker.template.TemplateModelException: No signature of method getJavaTypeName matches (java.lang.Object,java.lang.Boolean)

BUILD FAILED
C:\code\prj\build.xml:89: org.hibernate.tool.hbm2x.ExporterException: Error while processing template daohome.ftl
at org.hibernate.tool.ant.HibernateToolTask.reportException(HibernateToolTask.java:194)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:163)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
Caused by: org.hibernate.tool.hbm2x.ExporterException: Error while processing template daohome.ftl
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:249)
at org.hibernate.tool.hbm2x.TemplateProducer.produceToString(TemplateProducer.java:67)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.java:28)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.java:97)
at org.hibernate.tool.hbm2x.GenericExporter.exportPOJO(GenericExporter.java:112)
at org.hibernate.tool.hbm2x.GenericExporter.exportPersistentClass(GenericExporter.java:101)
at org.hibernate.tool.hbm2x.GenericExporter.exportClasses(GenericExporter.java:84)
at org.hibernate.tool.hbm2x.GenericExporter.doStart(GenericExporter.java:69)
at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java:93)
at org.hibernate.tool.hbm2x.GenericExporter.start(GenericExporter.java:59)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:40)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:160)
... 11 more
Caused by: freemarker.template.TemplateModelException: No signature of method getJavaTypeName matches (java.lang.Object,java.lang.Boolean)
at freemarker.ext.beans.MethodMap.getMostSpecific(MethodMap.java:191)
at freemarker.ext.beans.OverloadedMethodModel.exec(OverloadedMethodModel.java:105)
at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.IfBlock.accept(IfBlock.java:82)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.Environment.visit(Environment.java:233)
at freemarker.core.BlockAssignment.accept(BlockAssignment.java:83)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.Environment.process(Environment.java:176)
at freemarker.template.Template.process(Template.java:231)
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:243)
... 22 more
--- Nested Exception ---
org.hibernate.tool.hbm2x.ExporterException: Error while processing template daohome.ftl
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:249)
at org.hibernate.tool.hbm2x.TemplateProducer.produceToString(TemplateProducer.java:67)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.java:28)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.java:97)
at org.hibernate.tool.hbm2x.GenericExporter.exportPOJO(GenericExporter.java:112)
at org.hibernate.tool.hbm2x.GenericExporter.exportPersistentClass(GenericExporter.java:101)
at org.hibernate.tool.hbm2x.GenericExporter.exportClasses(GenericExporter.java:84)
at org.hibernate.tool.hbm2x.GenericExporter.doStart(GenericExporter.java:69)
at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java:93)
at org.hibernate.tool.hbm2x.GenericExporter.start(GenericExporter.java:59)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:40)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:160)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
Caused by: freemarker.template.TemplateModelException: No signature of method getJavaTypeName matches (java.lang.Object,java.lang.Boolean)
at freemarker.ext.beans.MethodMap.getMostSpecific(MethodMap.java:191)
at freemarker.ext.beans.OverloadedMethodModel.exec(OverloadedMethodModel.java:105)
at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.IfBlock.accept(IfBlock.java:82)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.Environment.visit(Environment.java:233)
at freemarker.core.BlockAssignment.accept(BlockAssignment.java:83)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at freemarker.core.Environment.process(Environment.java:176)
at freemarker.template.Template.process(Template.java:231)
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:243)

I use hibernate3.1, HibernateTools-3.2.0.beta6 and oracle 10g
Any idea how to solve this?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 6:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
do you by any chance have composite id ?

i think maybe some part of the dao templates can't handle that well.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 6:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
do you by any chance have composite id ?

i think maybe some part of the dao templates can't handle that well.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 6:29 am 
Beginner
Beginner

Joined: Wed Aug 09, 2006 11:26 am
Posts: 20
Yes there are a few mappings that use composite ids.
I tried changing the template by removing the findById method that causes the problem (i suppose one can do that) but it behaves like the method is still there.

Is it possible to limit the template to the working functionality and implement the findById method myself? Or is it the composite ids that won't let me create daos at all?

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 6:33 am 
Beginner
Beginner

Joined: Wed Aug 09, 2006 11:26 am
Posts: 20
Yes there are a few mappings that use composite ids.
I tried changing the template by removing the findById method that causes the problem (i suppose one can do that) but it behaves like the method is still there.

Is it possible to limit the template to the working functionality and implement the findById method myself? Or is it the composite ids that won't let me create daos at all?

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 6:43 am 
Beginner
Beginner

Joined: Wed Aug 09, 2006 11:26 am
Posts: 20
Yes there are a few mappings that use composite ids.
I tried changing the template by removing the findById method that causes the problem (i suppose one can do that) but it behaves like the method is still there.

Is it possible to limit the template to the working functionality and implement the findById method myself? Or is it the composite ids that won't let me create daos at all?

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 9:27 am 
Regular
Regular

Joined: Mon May 22, 2006 4:28 am
Posts: 56
Location: Göteborg, Sweden
Hi Aragorn,
to fix this you need to edit your dao templates you are using to generate the code. For the method findById() you have a if statement
<#if clazz.identifierProperty>

simply change this one to:

<#if clazz.identifierProperty?has_content>

and it should work.

Max, mayby you should add this also for the next build.

Cheers,
Jacob


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 10:14 am 
Beginner
Beginner

Joined: Wed Aug 09, 2006 11:26 am
Posts: 20
Thanks for your reply jacob.

The daohome.ftl I use (found in hibernate_tools.jar) does not contain that if statement for method findById. I added it anyway but I still get the same error.

It seems not to locate the template. Should it be in a certain location?
I have hbm and java files in src folder as well as the template.

<target name="hbm2dao">
<hibernatetool destdir="${src}">
<configuration configurationfile="${src}/hibernate.cfg.xml"/>
<hbm2dao templatepath="${src}/daohome.ftl"/>
</hibernatetool>
</target>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 11:01 am 
Regular
Regular

Joined: Mon May 22, 2006 4:28 am
Posts: 56
Location: Göteborg, Sweden
aragorn wrote:
It seems not to locate the template. Should it be in a certain location?


You can use the "Hibernate code generation" tool inside eclipse and under main check "Use custom templates" and point that to your location.

What version are you using of Hibernate tools?


My Ant task look like this:
Code:
<target name="generateHibernateDaoInterfaceClasses">
      <hibernatetool>
         <configuration
         configurationfile="${hibernateRootDir}/hibernate.cfg.xml">            
            <fileset dir="${hibernateRootDir}">
               <include name="/namedqueries/*.hbm.xml"/>
            </fileset>
            <fileset dir="${hibernateMappingFileLocation}">
               <include name="*.hbm.xml"/>
            </fileset>
         </configuration>
         
         <hbmtemplate
            filepattern="{class-name}Dao.java"
            templatepath="${hibernateRootDir}/template/dao"
            template="daointerface.ftl"
            destdir="${hibernateDaoLocation}">
            <property key="jdk5" value="true"/>
            <property key="ejb3" value="false"/>
         </hbmtemplate>
      </hibernatetool>
   </target>



and here you can point out the location and name of the template


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 12:09 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Template path is the PATH to the template directory. Set the path to ${src} and create a dao directory under ${src}. If the directory structure and name of the template is the same as in the hibernate-tools.jar then it will pick them up automatically (in other words, if you have a dao directory under ${src} and a template contained therein named daohome.ftl, then you are all set). You probably want to create a template directory to avoid mixing classes and templates.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 11, 2006 3:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Jake123 wrote:
Hi Aragorn,
to fix this you need to edit your dao templates you are using to generate the code. For the method findById() you have a if statement
<#if clazz.identifierProperty>

simply change this one to:

<#if clazz.identifierProperty?has_content>

and it should work.

Max, mayby you should add this also for the next build.


could you guys put it as a patch in jira ? thanks.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 11, 2006 4:08 am 
Beginner
Beginner

Joined: Wed Aug 09, 2006 11:26 am
Posts: 20
Hello,
thanks everyone for your replies

The template seems to be found now but I get a new exception:
hbm2dao2:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: generic exporter
[hibernatetool] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[hibernatetool] log4j:WARN Please initialize the log4j system properly.
[hibernatetool] An exception occurred while running exporter #2:generic exporter
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.tool.hbm2x.ExporterException: Error while processing template daohome.ftl
[hibernatetool] freemarker.core.InvalidReferenceException: Expression sessionFactoryName is undefined on line 77, column 139 in daohome.ftl.

The config file looks like this:

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory name="java:/hibernate/HibernateFactory">

<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="connection.username">test</property>
<property name="connection.password">test</property> <property name="connection.pool_size">2</property>
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>

<!-- mappings -->

</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 11, 2006 4:11 am 
Beginner
Beginner

Joined: Wed Aug 09, 2006 11:26 am
Posts: 20
I am not sure about setting the session factory name, do I need anything more?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 11, 2006 5:20 am 
Beginner
Beginner

Joined: Wed Aug 09, 2006 11:26 am
Posts: 20
I found a solution to this by passing the session factory name as a parameter.

<hbmtemplate
filepattern="{class-name}Dao.java"
templatepath="${temp}"
template="daohome.ftl">
<property key="jdk5" value="false"/>
<property key="ejb3" value="false"/>
<property key="sessionFactoryName" value="java:/hibernate/HibernateFactory"/>
</hbmtemplate>

I managed to create the daos! but is there a way to tell the template to create the findById method with the wrapper type as a parameter e.g findById(Long id). Currently it gets created as findById(long id).
Is there a way to do that in the template without explicitly changing my hbm files to:

<id name="id" type="java.lang.Long">
<column name="ID" precision="10" scale="0" />
<generator class="sequence">
<param name="sequence">ASeq</param>
</generator>
</id>

Thank you all.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 11, 2006 5:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you hbm.xml is not using "assigned" it should just generate the java.lang.Long.

_________________
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.  [ 24 posts ]  Go to page 1, 2  Next

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.