我无法理解HQL到SQL的翻译

时间:2018-02-15 20:30:27

标签: java hibernate mariadb hql

为什么我这么简单 :before { font-family: "Font Awesome 5 Brands"; font-weight: 400; content: "\f167"; } 给出以下错误:

  

java.sql.SQLException:未知栏' shopping0_.product'在'字段列表'

这是映射文件Shopping.hbm.xml

List<Shopping> products = session.createQuery("FROM Shopping").list();

表格是:

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name = "com.konrad.market.Shopping" table = "BASKETS">
  <meta attribute = "class-description">
     This class contains the employee detail.
  </meta>
<composite-id>
<key-property name="basketID" column="basketid" type="int"  />
<key-property name="productID" column="product" type="string" />
</composite-id>
<property name="quantity" column="quantity" type="int" />
</class>
</hibernate-mapping>

basketid和产品也是外键。 有什么想法吗?

2 个答案:

答案 0 :(得分:0)

基于错误 - 表没有产品col。它叫做productId吗?你有没有在hbm文件中定义的复合键,你的db - on basketid和product。

答案 1 :(得分:0)

If basketid and product are foreign keys then you need to change the HBM mapping as I didn't see the mapping in hbm.