Incorrect syntax near the keyword 'table' and could not extract ResultSet

I have created a project with SQL Server which the files:*

  • is it possible execute a perl script with admin rights or as a specific user?
  • Updating SQL Table Where Fields May be Null
  • T-SQL COALESCE GROUPING SETS into single column without NULL duplicates
  • SQL Update only duplicate row
  • Using a tsql MERGE statement in SSIS to copy data between databases
  • Unable to Auto-Create ASPNETDB.MDF - Visual Web Developer Express 2008 / SQL Express 2008
  • public class UserDAO 
        private static SessionFactory sessionFactory;
            sessionFactory = HibernateUtility.getSessionFactory();
        public static List<User> findAll()
            Session session = sessionFactory.openSession();
            Criteria crit = session.createCriteria(User.class);
            List<User> userList = crit.list();
            return userList;

    public class UserService 
        public static void main(String[] args) 
            List<User> listUsers = UserDAO.findAll();
            for(User u : listUsers)
                System.out.println("User is = " + u.getUserName());


    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
           <property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
           <property name="hibernate.connection.driver_class"></property>
           <property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;database=happy</property>
           <property name="hibernate.connection.username">lm</property>
           <property name="hibernate.connection.password">pp</property>
           <property name="">create</property>
           <property name="show_sql">true</property>
           <property name="hibernate.current_session_context_class">thread</property>
           <property name="">validate</property>
           <mapping class="com.annotation.day1.entity.User"/>

    After running the project, the exception bellow displayed:

   as id1_0_0_,
            this_.password as password2_0_0_,
            this_.userName as userName3_0_0_ 
            User this_
    Aug 07, 2016 9:29:00 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    WARN: SQL Error: 156, SQLState: S0001
    Aug 07, 2016 9:29:00 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    ERROR: Incorrect syntax near the keyword 'User'.
    Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not extract ResultSet
        at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(
        at org.hibernate.loader.Loader.getResultSet(
        at org.hibernate.loader.Loader.executeQueryStatement(
        at org.hibernate.loader.Loader.executeQueryStatement(
        at org.hibernate.loader.Loader.doQuery(
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(
        at org.hibernate.loader.Loader.doList(
        at org.hibernate.loader.Loader.doList(
        at org.hibernate.loader.Loader.listIgnoreQueryCache(
        at org.hibernate.loader.Loader.list(
        at org.hibernate.loader.criteria.CriteriaLoader.list(
        at org.hibernate.internal.SessionImpl.list(
        at org.hibernate.internal.CriteriaImpl.list(
        at com.annotation.day1.dao.UserDAO.findAll(
        at com.annotation.day1.service.UserService.main(
    Caused by: Incorrect syntax near the keyword 'User'.

    Any help is appreciated. Thanks in advance.

  • How to prevent Hibernate formula annotation of adding table name before reserved words?
  • Issue with a date extraction in SQL Server
  • sql stop count at a given threshold
  • TSQL: Prevent trigger suppressing error but rolling back transaction
  • How to query two SQL tables with the same structure using criteria api?
  • Hibernate join Entities on a column of type varbinary?
  • One Solution collect form web for “Incorrect syntax near the keyword 'table' and could not extract ResultSet”

    USER is a Reserve Word and needs to be escaped in query using square bracket [] while querying.

    If you are using annotations, escape through single quotes. '', like below


    Also refer here for similar issue.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.