-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to retrieve column name from createNativeQuery
PostPosted: Thu Apr 15, 2010 5:35 pm 
Newbie

Joined: Wed Apr 14, 2010 10:33 pm
Posts: 1
I have tried variety of approaches and it seems there is no easy way to obtain the column names from a SP where is being returning the result sets as List<Object[]>.

The following is my code snip:

List<Object[]> list = null;
try
{
Query query = em.createNativeQuery("{call
dbo.usp_sel_PlayerContact(?)}", "getPlayerContactByPlayerIdSPMapping").setParameter(1, playerId);

list = query.getResultList();

for (Iterator iterator = list.iterator(); iterator.hasNext();)
{
Object[] objReturns = (Object[]) iterator.next();
for (int i = 0; i < objReturns.length; i++)
{
System.out.print(objReturns[i] + " :: ");
}
System.out.println(" ");
}
return list;
}
catch(NoResultException e)
{
return null;
}

Also, my entity bean code snip for mapping column name is:

@NamedNativeQueries({
@NamedNativeQuery(name="getPlayerContactByPlayerIdSP", resultSetMapping="getPlayerContactByPlayerIdSPMapping",
query="{call dbo.usp_sel_PlayerContact(?)}",
hints={
@QueryHint(name="org.hibernate.callable", value="true")
})
})

@SqlResultSetMappings({
@SqlResultSetMapping(name="getPlayerContactByPlayerIdSPMapping",
columns={
@ColumnResult(name="playerid"),
@ColumnResult(name="contactentityid"),
@ColumnResult(name="nickname"),
@ColumnResult(name="entitytypeid"),
@ColumnResult(name="entitytypename"),
@ColumnResult(name="statusid"),
@ColumnResult(name="statusname"),
@ColumnResult(name="namespaceid"),
@ColumnResult(name="namespacename"),
@ColumnResult(name="namespaceidentity"),
@ColumnResult(name="Handle"),
@ColumnResult(name="ForumUserID"),
@ColumnResult(name="SiteID"),
@ColumnResult(name="OrgName"),
@ColumnResult(name="SiteCity"),
@ColumnResult(name="SiteState"),
@ColumnResult(name="UserName")
})
})


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.