]
Joe Porcheddu commented on HBX-469:
-----------------------------------
Created HBX-1065 and attached test case.
Named Query DAO methods with Primitive types fail to compile
------------------------------------------------------------
Key: HBX-469
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HBX-469
Project: Hibernate Tools
Issue Type: Bug
Components: hbm2java
Affects Versions: 3.1beta1
Reporter: James Schopp
Fix For: 3.2beta6
if you define a name query that receives a primitive or wrapper parameter, then the DAO
method for the name query will always be generated with "primitive" type. This
failsto compile, since the call to query.setParameter("paramName", value); takes
an object, not a primitive. For example:
<query name="com.mycom.persistence.Account.findCommercialAccountById">
from Account where accountTypeClass='C' and accountNumber=:accountNumber
<query-param name="accountNumber" type="java.lang.Long" />
</query>
This generates the code
public List findCommercialAccountById(long accountNumber) {
Query query = getSession(false)
.getNamedQuery("com.alldata.ecis.persistence.Account.findCommercialAccountById");
query.setParameter("accountNumber", accountNumber);
return query.list();
}
This code does not compile.
I beleive the fix might be as simple as modifying Cfg2JavaTool.asFinderArgumentList():
if ( type instanceof PrimitiveType ) {
typeClass = ( (PrimitiveType) type ).getPrimitiveClass();
}
else {
typeClass = type.getReturnedClass();
}
I think this should always return the type.getReturnedClass(), and never the
primitive...
ALSO: it would ne nice to have another Cfg2JavaTool function like
asFinderArgumentList
but that generates the list as parameters to the call, not the function definition.
For example, if a named query takes params:
Long accountNumer, String accountName
then, maybe have function called
asFinderCallerArgumentList()
which would return
accountNumer, accountName
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: