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;
<property name="connection.driver_class"> com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.url">jdbc:sqlserver://localhost;databaseName=test;integratedSecurity=true;</property>
<property name="connection.username">not required</property>
<property name="connection.password"></property>
<property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="user.hbm.xml"/>
Here is user.hbm.xml
<class name="ammar.User" table="user" schema="dbo" catalog="test">
<id name="userId" type="int" column="userId" >
<generator class="assigned"/>
</id>
<property name="userName">
<column name="userName" />
</property>
</class>
And here is code I'm using to get data from database.
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");
SQLGrammarException as well as SQLServerException occurs when I run this.
Urgent reply is needed.
Best Answer
Solved. Actually 'user' a is reserved word in SQL Server 2008. Anyhow, Thanks to @ManuPK.