title: Retrieve single row and single column using hibernate
body: <p>I know how to retrieve multiple columns or rows or both using the Hibernate method below. However am not sure how to retrieve only a single row or column and assign it to a String variable. Any help on this? Thanks</p>
  
  <pre><code>    Session session = getSessionFactory().beginSession();
      Transaction transaction = null;
  
      StringBuilder sql = new StringBuilder();
  
      sql.append("SELECT DISTINCT B.COLUMN_NAME ");
      sql.append("FROM ALL_CONSTRAINTS A, ALL_CONS_COLUMNS B, ARCTBL C ");
      sql.append("WHERE A.TABLE_NAME = :TABLE_NAME AND A.CONSTRAINT_TYPE = 'P' "); 
      sql.append("AND A.CONSTRAINT_NAME = B.CONSTRAINT_NAME ");
      sql.append("AND C.TABLENAME=A.TABLE_NAME AND A.TABLE_NAME=B.TABLE_NAME ");
  
      try{
  
      **listOfValues = session.createSQLQuery(sql.toString()).setParameter("TABLE_NAME", table).list();**
      //Change this to code below
  String returnObjByHibernate = session.createSQLQuery(//Hibernate method)
      transaction.commit;
      }
      catch (Exception e){
      //Logic here
  </code></pre>