|
From: Jak M. (JIRA) <no...@at...> - 2006-07-05 18:10:04
|
Incorrect code generation for query-param elements
--------------------------------------------------
Key: HHH-1882
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1882
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.1.3
Environment: Hibernate 3/MySql 5.X
Reporter: Jak Mang
Query params in xml mapping files generate incorrect code for integers and possibly other scalers. In the case below,
I have tried "int", "integer", "Integer" and "java.lang.Integer" and "Ljava.lang.Integer;" for the type of parameter "region".
<query name="com.tgcusa.idmgr.ProgramId.findProgramId">
<query-param name="region" type="integer"/>
<query-param name="epgser" type="string"/>
<query-param name="epgepi" type="string"/>
<![CDATA[
select pid.tgcsh, pid.tgcser, pid.tgcepi from com.tgcusa.idmgr.ProgramId
as pid where pid.region == :region and pid.epgser == :epgser and
pid.epgepi = :epgepi
]]>
</query>
The code generator always produces:
public List findTgcSerForEpgSer(int region, java.lang.String tepgser)
{
Query query =
sessionFactory.getCurrentSession().getNamedQuery("com.tgcusa.idmgr.ProgramId.findTgcSerForEpgSer");
query.setParameter("region", region);
query.setParameter("tepgser", tepgser);
return query.list();
}
Which has the compilation error:
[javac] Found 2 semantic errors compiling "/sandbox/mainline/srcroot/sw/tgcs
vc/lib/java/src/com/tgcusa/idmgr/ProgramIdHome.java":
[javac] 171. query.setParameter("region", region);
[javac] ^----------------------------------^
[javac] *** Semantic Error: No applicable overload for a method with signatu
re "setParameter(java.lang.String, int)" was found in type "org.hibernate.Query"
. Perhaps you wanted the overloaded version "org.hibernate.Query setParameter(ja
va.lang.String $1, java.lang.Object $2) throws org.hibernate.HibernateException;
" instead?
It seems that:
1) There is ambiguity about the type "integer". I have seen it generate java.lang.Integer in other code.
2) for "int", a query.setParameter should support int.
3) for an Integer object, the setParameter call is ok, but the the method parameter shoud be Integer not int.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
|