Link to home
Start Free TrialLog in
Avatar of Squadless
Squadless

asked on

Reading ResultList from @NamedQuery EJB3 in JAVA

I have a @NamedQuery which is essentially 1 select stmtnt and return 1 field from the server and i have no problem obtaining that value using the code below:
countOfBills = qry.getSingleResult();

But when I create a @NamedQuery which returns multiple rows of fields, the only feasible solution is to use

Query qry = m_BillingEntityManager.createNamedQuery("GetTaxDetails")      .setParameter("bID", lBillId);
List lTaxObjects= qry.getResultList();
...
however I cannot do anything with this list for some reason... it throws classcastexception if i try to cast it to anything other then (Object)...

I've read that the system knows to return that particular object from which the query is being executed so i've changed it explicitly to be a list of TAX objects but then im still at the same problem...
List<Tax> lTaxObjects= qry.getResultList();

am i missing some constructor or something in my EJB class (Tax class)?
all i have there are getters/ setters/ @named querries and the fields ..

Thanks
Avatar of ramazanyich
ramazanyich
Flag of Belgium image

could you provide you named query ?
Avatar of Squadless
Squadless

ASKER

     @NamedQuery
      (
                  name = "GetTaxDetails",
                  query = "select T.billId, T.description, T.amount from TaxDO T where T.billId=:bID " +
                    "order by T.taxAuthority "
    )
i get back a list of objects, i iterate through them fine and the result matches the results from db, but i cannot get it assigned to the object that i need... im thinking i am missing a mechanism which does that... maybe an annotation?
ASKER CERTIFIED SOLUTION
Avatar of ramazanyich
ramazanyich
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hahahaha WOW that did the trick... sigh...im such a moron...

THANKS!!!!!!!!!!!!!!!!!!!!
perfect