Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

how to set multiple column query not java.lang.Object

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all!
Is there a way to convert the return type of multiple column queries into my own referenced type?
Example, my query statement is "SELECT rfqItemId, itemNumber FROM RFQItems". the return type of each element data retrieved is Object[2], I want it to be RFQItems. Currently, I'm querying the entire table but this kinda makes the query slow. I would like to query at least just these two columns for a particular process.
By the way, I'm using Jboss SEAM framework. And below is one of the codes that I want to optimize...

@NamedQuery(
name="RFQItems.listAll",
query="SELECT c.rfqItemId,c.item FROM RFQItems c WHERE c.recordStatus=true"),

public List<RFQItems> getListAll()
{
List<RFQItems> instance = getEntityManager().createNamedQuery("RFQItems.listAll").getResultList();
return instance;
}

An error occurs in the code above when I'll try to parse each data element of instance to RFQItems.
It would help if you'll also post a sample code.

Thanks in advance!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dennis,

I think you could have your own custom java object call RFQItem with just the 2 fields called rfqItemId, itemNumber. and then in the named query you could write something like this


Rest all should be automatically taken care for you.

Note: we are creating a new object RFQItem in the query itself, and so you would have to use the correct RFQItem in the List<> type. This should most likely work for you ...


 
Your mother is a hamster and your father smells of tiny ads!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic