关于hibernate的 org.hibernate.exception.SQLGrammarException: 50
用hibernate时遇到这个报错,下面是代码,很简单的用户和订单一对多情况,在测试删除user时,报的错报错严重:YouhaveanerrorinyourSQLsynt...
用hibernate时遇到这个报错,下面是代码,很简单的用户和订单一对多情况,在测试删除user时,报的错
报错
严重: 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 'order orders0_ where orders0_.userid=22' at line 1
org.hibernate.exception.SQLGrammarException: could not initialize a collection:
user.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cn.com.yifxiang.mobileShop.entity">
<class name="User" table="user">
<id name="userId" column="userid">
<generator class="increment"></generator>
</id>
<property name="userName" column="username"></property>
<property name="password" column="password"></property>
<one-to-one name="userInfo" class="UserInfo" cascade="all" property-ref="user"></one-to-one>
<set name="orders" cascade="all" inverse="true" >
<key column="userid"></key>
<one-to-many class="Order"/>
</set>
<!-- <set name="evaluates" cascade="all" inverse="true">
<key column="userid"></key>
<one-to-many class="Evaluate"/>
</set>
<set name="addresses" cascade="all" inverse="true">
<key column="userid"></key>
<one-to-many class="Address"/>
</set> -->
</class>
</hibernate-mapping>
order.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cn.com.yifxiang.mobileShop.entity">
<class name="Order" table="order">
<id name="orderId" column="orderid">
<generator class="increment"></generator>
</id>
<property name="coat" column="coat"></property>
<property name="date" column="date"></property>
<!--
<set name="orderLine" cascade="all" inverse="true">
<key column="orderid"></key>
<one-to-many class="OrderLine"/>
</set> -->
<!-- <many-to-one name="orderStatus" class="OrderStatus" column="orderstatusid"></many-to-one>
<many-to-one name="payway" class="Payway" column="paywayid"></many-to-one> -->
<many-to-one name="user" class="User" column="userid"></many-to-one>
<!-- <many-to-one name="address" class="Address" column="addressid"></many-to-one> -->
</class>
</hibernate-mapping> 展开
报错
严重: 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 'order orders0_ where orders0_.userid=22' at line 1
org.hibernate.exception.SQLGrammarException: could not initialize a collection:
user.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cn.com.yifxiang.mobileShop.entity">
<class name="User" table="user">
<id name="userId" column="userid">
<generator class="increment"></generator>
</id>
<property name="userName" column="username"></property>
<property name="password" column="password"></property>
<one-to-one name="userInfo" class="UserInfo" cascade="all" property-ref="user"></one-to-one>
<set name="orders" cascade="all" inverse="true" >
<key column="userid"></key>
<one-to-many class="Order"/>
</set>
<!-- <set name="evaluates" cascade="all" inverse="true">
<key column="userid"></key>
<one-to-many class="Evaluate"/>
</set>
<set name="addresses" cascade="all" inverse="true">
<key column="userid"></key>
<one-to-many class="Address"/>
</set> -->
</class>
</hibernate-mapping>
order.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cn.com.yifxiang.mobileShop.entity">
<class name="Order" table="order">
<id name="orderId" column="orderid">
<generator class="increment"></generator>
</id>
<property name="coat" column="coat"></property>
<property name="date" column="date"></property>
<!--
<set name="orderLine" cascade="all" inverse="true">
<key column="orderid"></key>
<one-to-many class="OrderLine"/>
</set> -->
<!-- <many-to-one name="orderStatus" class="OrderStatus" column="orderstatusid"></many-to-one>
<many-to-one name="payway" class="Payway" column="paywayid"></many-to-one> -->
<many-to-one name="user" class="User" column="userid"></many-to-one>
<!-- <many-to-one name="address" class="Address" column="addressid"></many-to-one> -->
</class>
</hibernate-mapping> 展开
10个回答
展开全部
mysql语法错误了,薯让喊检查order orders0_ where orders0_.userid=22这附近滑瞎,数野修改下就好了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
数据表当中存在当前数据库的 关键字 所以会这样
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
删除user那个语句放 出来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
检查下sql里培猛神是否有 role 这配亏个字段。看看数据库是否没有这个column。
应该是sql和数据结构不匹配导致的。
同时注意下知宴role的大小写吧 ,有的时候数据库会区分大小写的。
应该是sql和数据结构不匹配导致的。
同时注意下知宴role的大小写吧 ,有的时候数据库会区分大小写的。
追问
您看清楚问题好吗,不要随便复制
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
今天我也遇局埋到了nested exception is org.hibernate.exception.SQLGrammarException: Error accessing tables metadata,究桐指蚂其原因是数据库有问题,逗毕建议重新建立一个数据库database,然后对新的database进行操作。亲测有效。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询