title: Need solution for casting uniqueresult fetched through jpa to String array
body: <p>When fetching multiple rows through hibernate I used below logic to read each row entry. Working with Hibernate 4 and Websphere 7 </p>
  
  <pre><code>@SuppressWarnings("unchecked")
  List&lt;Object[]&gt; objectList = new ArrayList&lt;Object[]&gt;(query.getResultList());\
  
  for (Object[] record : objectList) {
      String entry1 = (String.valueOf(record[0]));
      String entry2 = (String) record[1];
  }
  </code></pre>
  
  <p>Now I am trying fetch one single row. When trying to cast it fails.</p>
  
  <pre><code>Object[] result = (Object[])query.uniqueResult();
  if(result != null) {
      resultDetails [0] = (String)result[0];
      resultDetails [1] = (String)result[1];
  }
  </code></pre>
  
  <p>When trying to set String[] as entity it fails for obvious reasons. String[] cannot be used as entity.</p>
  
  <p>Tried copying the object into the array</p>
  
  <pre><code>Object[] result = (Object[])query.uniqueResult();
  logger.info(result + " -- Length --&gt; " + result.length);
  </code></pre>
  
  <p>Output for the above 2 statement is <strong>[Ljava.lang.Object;@41a841a8 -- Length --> 2</strong></p>
  
  <p>Followed statement to copy array which fails</p>
  
  <pre><code>String[] resultDetails = Arrays.asList(result).toArray(new String[result.length]);
  </code></pre>
  
  <p>even using copyof it fails
      Arrays.copyOf(result, result.length, String[].class);</p>
  
  <p>Need to understand workaround solution for this. Which works without creating new entity class</p>
  
  <p><strong>---- Update to the code which works for me as a solution.</strong></p>
  
  <pre><code>  Object[] result = (Object[])query.uniqueResult(); int i = 0;
    quoteOwnerDetails= new String[result.length];
    for(Object obj : result){
       System.out.println(obj);
       quoteOwnerDetails[i] = obj.toString(); i++;
    }
  </code></pre>
  
  <p>I identified the 2nd value was integer due to which the case was failing. Doing toString on the individual values solves it.</p>
  
  <p>Please update if you have any other solution to this beside creating a new Entity class.</p>