title: SQL Server - Hibernate select SQL statement
body: <p>I am trying to use Hibernate with SQL Server .</p>
  
  <p>I want to select the rows from SQL Server and cast them to Places objects. </p>
  
  <p>I will write the codes I tried and exceptions I got. </p>
  
  <pre><code>List places = session.createQuery("FROM PLACES").list();
  for (Iterator iterator = places.iterator(); iterator.hasNext();){
     Place place = (Place) iterator.next(); 
  }
  </code></pre>
  
  <p>Exception: </p>
  
  <pre><code>SEVERE: Incorrect syntax near the keyword 'from'.
  </code></pre>
  
  <p>This code generates </p>
  
  <pre><code>select  from  
  </code></pre>
  
  <p>and since SQL Server needs something between select and from this query fails </p>
  
  <p>So I tried to change the code to </p>
  
  <pre><code>List places = session.createSQLQuery("SELECT ID,NAME FROM [PLACES].[dbo].[PLACES]").list();
     for (Iterator iterator = places.iterator(); iterator.hasNext();){
        Place place = (Place) iterator.next(); 
     }
  </code></pre>
  
  <p>Exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException
  </code></pre>
  
  <p>Since this query returns an Object[] I can not cast it.</p>
  
  <p>How can I get rows and cast them to Places objects</p>
  
  <p>Mapping </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name="com.places.general.Place" table="PLACES" schema="dbo"&gt;
          &lt;id name="id" type="int"&gt;
              &lt;column name="ID"/&gt;
              &lt;generator class="identity"/&gt;
          &lt;/id&gt;
          &lt;property name="name" type="string"&gt;
              &lt;column length="100" name="NAME" not-null="true"/&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>