Hi everyone,
I am facing a problem retriveing the Maximum ID from a table called "Memo".
In ejb-jar.xml file I have defined the query in the following manner-
<query-method>
<method-name>findMaxID</method-name>
<method-params/>
</query-method>
<ejb-ql><![CDATA[SELECT max(a.id) FROM Memo AS a]]></ejb-ql>
and in the LocalHome interface the method has been declared as below -
MemoLocal findMaxID ( ) throws FinderException;
But when I call this findMaxID() function from my session bean in the following -
public int findMaxIDInMemo()throws NamingException, FinderException
{
MemoLocalHome memoLocalHome;
MemoLocal memoLocal;
int iRetVal = 0;
try
{
memoLocalHome = this.getMemoLocalHome();
memoLocal = memoLocalHome.findMaxID();
iRetVal = Integer.parseInt(memoLocal.getId().toString());
RetVal ++;
} catch (Throwable e)
{
e.printStackTrace();
}
return iRetVal;
}
I get this error-
javax.ejb.FinderException: Find failed: java.sql.SQLException: Got a java.lang.Long[cl=0, value=1]
The problem is that finder methods can only return instances or collections of instances of the entity bean where the finder is, and max(a.id) returns an ID, not an instance.