Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Reading ResultList from @NamedQuery EJB3 in JAVA

Posted on 2009-12-30
6
Medium Priority
?
555 Views
Last Modified: 2013-11-24
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
0
Comment
Question by:Squadless
  • 4
  • 2
6 Comments
 
LVL 19

Expert Comment

by:ramazanyich
ID: 26149096
could you provide you named query ?
0
 
LVL 1

Author Comment

by:Squadless
ID: 26149158
     @NamedQuery
      (
                  name = "GetTaxDetails",
                  query = "select T.billId, T.description, T.amount from TaxDO T where T.billId=:bID " +
                    "order by T.taxAuthority "
    )
0
 
LVL 1

Author Comment

by:Squadless
ID: 26149163
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?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 19

Accepted Solution

by:
ramazanyich earned 2000 total points
ID: 26151081
If you want casting to object then your query should not contain object fields, but object itself.
eg.
  @NamedQuery
      (
                  name = "GetTaxDetails",
                  query = "select T from TaxDO T where T.billId=:bID " +
                    "order by T.taxAuthority "
    )
0
 
LVL 1

Author Comment

by:Squadless
ID: 26285589
hahahaha WOW that did the trick... sigh...im such a moron...

THANKS!!!!!!!!!!!!!!!!!!!!
0
 
LVL 1

Author Closing Comment

by:Squadless
ID: 31671286
perfect
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question