java - Retrieving the first item from the list and converting it in int -


i have following class shown below

public class brokerinvoicelineitem {       private int attachmentcount;  public int getattachmentcount() {         return attachmentcount;     }      public void setattachmentcount(int attachmentcount) {         this.attachmentcount = attachmentcount;     } } 

the named query in xml

<sql-query name="attachmentquery">      <![cdata[select count(iilnmp.inv_line_note_id) ioa_inv_line_note_map iilnmp ,                                                  ioa_invoice_line_notes iiln , ioa_invoice_line iil                                                  iilnmp.inv_line_note_id = iiln.id , iiln.inli_id =iil.id , iil.id = ?]]> </sql-query> 

now below operation doing list @ index 0 retrieving value getting compilation error need cast value stored @ index 0 int type able set please advise how can achieve same

query query = session.getnamedquery("attachmentquery");                 query.setparameter(0, itrbrokerinvoicelineitem.getid());                 list attachcount = query.list();                 if (attachcount != null && attachcount.size() > 0) {                     if (attachcount.get(0) != null) {                         itrbrokerinvoicelineitem.setattachmentcount(attachcount.get(0));                     }                 } 

the compilation error getting the method setattachmentcount(int) in type brokerinvoicelineitem not applicable arguments (object)

i have edited question please using hibernate 3.1 in query.getsingleresult method not there please advise

replace

list attachcount = query.list(); 

with this

list<integer> attachcount = (list<integer>) query.list(); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -