Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
dennis laping
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!
 
P Crasta
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 ...


 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic