I am using SQL Server 2008 with Hibernate 3.0 at the data access level of my application. The problem is that I cannot read from the database. Here is my Hibernate configuration;
<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 the user 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 the code that I use to get data from the 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");
A SQLGrammarException, as well as a SQLServerException, is thrown when I run this. An urgent response is required.
source share