title: Using Hibernate with SQL Server 2008
body: <p>I'm using SQL Server 2008 with Hibernate 3.0 at data access layer of my application. The problem is that I'm unable to read from database.
  Here is my Hibernate config;</p>
  
  <pre><code>&lt;property name="connection.driver_class"&gt; com.microsoft.sqlserver.jdbc.SQLServerDriver&lt;/property&gt;
  &lt;property name="connection.url"&gt;jdbc:sqlserver://localhost;databaseName=test;integratedSecurity=true;&lt;/property&gt;
  &lt;property name="connection.username"&gt;not required&lt;/property&gt;
  &lt;property name="connection.password"&gt;&lt;/property&gt;
  &lt;property name="dialect"&gt;org.hibernate.dialect.SQLServer2008Dialect&lt;/property    
  &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;    
  &lt;mapping resource="user.hbm.xml"/&gt;
  </code></pre>
  
  <p>Here is user.hbm.xml</p>
  
  <pre><code>&lt;class name="ammar.User" table="user" schema="dbo" catalog="test"&gt;
      &lt;id name="userId" type="int" column="userId" &gt;
          &lt;generator class="assigned"/&gt;
      &lt;/id&gt;
  
      &lt;property name="userName"&gt;
          &lt;column name="userName" /&gt;
      &lt;/property&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>And here is code I'm using to get data from database.</p>
  
  <pre><code>    SessionFactory sF = new Configuration().configure().buildSessionFactory();
      Session session = sF.openSession();
  
      User user = (User) session.get(User.class, 1);
  
      if(user!=null)
          System.out.println(user.getUserName());
      else
          System.out.println("Not Found");
  </code></pre>
  
  <p>SQLGrammarException as well as SQLServerException occurs when I run this.
  Urgent reply is needed.</p>