title: Hibernate JPA Native Query ResultSet
body: <p>I need to get a resultset via executing a native query in Hibernate. Though I am using EntityManager, the query and resultSet may not be entities. </p>
  
  <p>A need to get ResultSet that is of List. Since the select output may vary (read dynamic) i cannot use  SqlResultSetMapping. </p>
  
  <p>When i tried the below code i got a result. Since what i am requesting is a single valued result. (Hibernate JPA)</p>
  
  <pre><code>Query query = manager.createNativeQuery("select name from fresher_test where id=1");
  List&lt;Object&gt; amount = query.getResultList();
  
  if(amount == null)
   {
      System.out.println("Hey its a null");
      return;
   }
   for(Object e : arr)
   {
     System.out.println(e.toString());
   }
  </code></pre>
  
  <p>The output was : Alice  </p>
  
  <p>When I tried to get more than one select out from the same code with Query as <strong>select name,designation from fresher_test where id=1</strong></p>
  
  <p>The output was : [Ljava.lang.Object;@8b1a4f</p>
  
  <p>An object. How do I get the fields from this object?. I tried to typecast object e (List l = (List) e;) to a List but i throws java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List.</p>
  
  <p>This there a way that I could get the values in a List or Array ??</p>
  
  <p>Note : I cannot use a result class/entity since the results could be dynamic.</p>