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") }) })
|