您的位置:首页 > 数据库 > MySQL

You have an error in your SQL syntax; check the manual that corresponds to your MySQL 完美解决

2016-05-16 14:11 633 查看
 1.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '5 cproduct0_.id as id0_, cproduct0_.bphoto as bphoto0_, cproduct0_.carMessage as' at line 1

   2.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '5 cproduct0_.id as id0_, cproduct0_.bphoto as bphoto0_, cproduct0_.carMessage as' at line 1

遇到这种情况,要看控制台输出的语句

Hibernate: 

    select

        top 5 cproduct0_.id as id0_,

        cproduct0_.bphoto as bphoto0_,

        cproduct0_.carMessage as carMessage0_,

        cproduct0_.created as created0_,

        cproduct0_.price as price0_,

        cproduct0_.sphoto as sphoto0_,

        cproduct0_.status as status0_,

        cproduct0_.tags as tags0_,

        cproduct0_.text as text0_,

        cproduct0_.title as title0_,

        cproduct0_.updated as updated0_,

        cproduct0_.video as video0_ 

    from

        c_product cproduct0_

我将这个带进去我的mysql数据查询说语句错误,然后将top5删除之后就可以了,因为mysql是不支持top的,所以不应该出现top 我出现top的原因是这里

看好了

<property name="hibernateProperties">

            <props>

                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>

                <prop key="hibernate.hbm2ddl">update</prop>

                <prop key="hibernate.show_sql">true</prop>

                <prop key="hibernate.format_sql">true</prop>

                <!--<prop key="hibernate.current_session_context_class">thread</prop> -->

            </props>

  </property>

看出问题了吗。问题出现在第一个方言

  <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>

这个是sqlserver的并不是mysql的,所以才会出现top。

改为

<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>

这就对了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息