title: JPA Native query get a Single Object
body: <p>How can i get a single object by using JPA Native query. I did some researches but all give an answer is use "getSingleResult", however it didn't return what i want to get. For example, what should i do if i want to get a count of table in my database and fetch it into a Integer.</p>
  
  <p>This code below shows how i get this by using Sessison hibernate:</p>
  
  <pre><code>int check = Integer.parseInt((String) sessionF.createSQLQuery("select to_char(count(*)) as count from user_tables where table_name upper('TEST')").uniqueResult()); 
  </code></pre>
  
  <p>And what i hope to be fine in JPA:</p>
  
  <pre><code>int check = Integer.parseInt((String) getEntityManager().createNativeQuery("select to_char(count(*)) as count from user_tables where table_name upper('TEST')").getSingleResult()); 
  </code></pre>
  
  <p>Obviously, the code doesn't return what i want. Therefore, please help me to cope with this problem. Thank you !</p>