-->
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: Named query & JPA: Undefined parameters while generating DAO
PostPosted: Mon Mar 01, 2010 8:00 am 
Newbie

Joined: Mon Mar 01, 2010 7:17 am
Posts: 10
Hi everyone,

I am currently trying to generate methods on a DAO Home, for each named query that is defined on a JPA entity.
Unfortunately, the NamedQueryDefinition object that I get from Configuration.getNamedQueries(queryName) does not have a valid parameterTypes Map. The return Map is null, causing the my template to fail.
I searched the forum and found out another post that seems to be related (viewtopic.php?f=6&t=1001745&p=2422898).
Furthermore, I also tried to put the query outside the class definition, on an orm.xml file, without success.

My question is: does Hibernate Tools support JPQL named queries and is it able to interpret them in order to extract their parameter types?

The error I'm facing is (I've omitted package names on my classes):

Code:
[hibernatetool] Executing Hibernate Tool with a JPA Configuration
[hibernatetool] 1. task: generic exporterclass: <...>.EAOExportertemplate: eaohome.ftl
15 [main] INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.4.0.GA
01-mar-2010 12:48:36 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.3
01-mar-2010 12:48:36 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
01-mar-2010 12:48:36 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
01-mar-2010 12:48:36 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
187 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.1.0.GA
187 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.4.0.GA
390 [main] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: <...>.Contact
406 [main] INFO org.hibernate.cfg.annotations.QueryBinder - Binding Named query: Contact.findByEmail => SELECT c FROM Contact WHERE c.email= :email
453 [main] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity <...>.Contact on table CONTACT
500 [main] INFO org.hibernate.cfg.AnnotationConfiguration - Hibernate Validator not found: ignoring
01-mar-2010 12:48:36 org.hibernate.tool.Version <clinit>
INFO: Hibernate Tools 3.2.4.GA
01-mar-2010 12:48:36 freemarker.log.JDK14LoggerFactory$JDK14Logger error
GRAVE:

Error on line 45, column 1 in eaohome.ftl
cfg.namedQueries.get(queryName).parameterTypes is undefined.
It cannot be assigned to params
The problematic instruction:
----------
==> assignment: params=cfg.namedQueries.get(queryName).parameterTypes [on line 45, column 1 in eaohome.ftl]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Error on line 45, column 1 in eaohome.ftl
cfg.namedQueries.get(queryName).parameterTypes is undefined.
It cannot be assigned to params
        at freemarker.core.Assignment.accept(Assignment.java:111)
        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.ConditionalBlock.accept(ConditionalBlock.java:79)
        at freemarker.core.Environment.visit(Environment.java:196)
        at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:160)
        at freemarker.core.Environment.visit(Environment.java:351)
        at freemarker.core.IteratorBlock.accept(IteratorBlock.java:95)
        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:232)
        at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:255)
        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:103)
        at org.hibernate.tool.hbm2x.GenericExporter.exportPOJO(GenericExporter.java:148)
        at org.hibernate.tool.hbm2x.GenericExporter.exportPersistentClass(GenericExporter.java:137)
        at org.hibernate.tool.hbm2x.GenericExporter$2.process(GenericExporter.java:43)
        at org.hibernate.tool.hbm2x.GenericExporter.doStart(GenericExporter.java:128)
        at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java:95)
        at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:40)
        at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        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:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at ise.antelope.tasks.IfTask.doIf(IfTask.java:298)
        at ise.antelope.tasks.IfTask.execute(IfTask.java:267)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        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:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:118)
        at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:98)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[hibernatetool] An exception occurred while running exporter #2:generic exporterclass: <...>.EAOExportertemplate: eaohome.ftl
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.tool.hbm2x.ExporterException: Error while processing Entity: <...>.Contact with template eaohome.ftl
[hibernatetool] freemarker.core.InvalidReferenceException: Error on line 45, column 1 in eaohome.ftl
[hibernatetool] cfg.namedQueries.get(queryName).parameterTypes is undefined.
[hibernatetool] It cannot be assigned to params
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An Ant BuildException has occured: org.hibernate.tool.hbm2x.ExporterException: Error while processing Entity: <...>.Contact with template eaohome.ftl

Error on line 45, column 1 in eaohome.ftl
cfg.namedQueries.get(queryName).parameterTypes is undefined.
It cannot be assigned to params


Here's an example entity:
Code:
@Entity
@Table(name = "CONTACT")
@NamedQuery(name = "Contact.findByEmail", query = "SELECT c FROM Contact WHERE c.email= :email")
public class Contact {
   ...
}


And here's the part of the template that is failing:
Code:
<#assign params = cfg.namedQueries.get(queryName).parameterTypes>

This line was borrowed from daohome.ftl, which is able to generate Hibernate-specific methods, based on named queries.
I looked and the NamedQueryDefinition object is not null, unlike its parameter types map.

Environment data:
Hibernate Tools - 3.2.4GA
Hibernate Core - 3.2.3GA
Hibernate EntityManager - 3.4.0GA
Hibernate Annotations - 3.4.0GA
Hibernate Commons Annotations - 3.1.0GA

Thanks in advance.

Regards,
Nuno Guerreiro


Top
 Profile  
 
 Post subject: Re: Named query & JPA: Undefined parameters while generating DAO
PostPosted: Fri Mar 12, 2010 3:34 am 
Newbie

Joined: Mon Mar 01, 2010 7:17 am
Posts: 10
ping


Top
 Profile  
 
 Post subject: Re: Named query & JPA: Undefined parameters while generating DAO
PostPosted: Fri Mar 12, 2010 4:41 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
hi, just a tip..I've noticed your named query has an error:
query = "SELECT c FROM Contact As c WHERE c.email= :email" (alias missing for Contact)

maybe that's not source of your problem but now it's better than before...

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: Named query & JPA: Undefined parameters while generating DAO
PostPosted: Fri Mar 12, 2010 5:49 am 
Newbie

Joined: Mon Mar 01, 2010 7:17 am
Posts: 10
Hi

Thanks but I have already changed it to:
@NamedQuery(name = "Contact.findByEmail", query = "SELECT c FROM Contact c WHERE c.email= ?1")

The error is still the same after changing the query.

Regards,
Nuno Guerreiro


Top
 Profile  
 
 Post subject: Re: Named query & JPA: Undefined parameters while generating DAO
PostPosted: Mon May 09, 2011 4:31 pm 
Newbie

Joined: Sat May 07, 2011 9:56 pm
Posts: 7
I'm sorry to resurrect such an old thread, but I am currently having a problem in which I cannot even get the named queries generated by the Hibernate Tools plugin for eclipse.

Is there some special configuration that I need to provide to accomplish that? I've got the configuration tool options set to export Domain Code only. Do I need anything else set?

Thanks,

Eric


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.