【问题标题】:I can't understand HQL to SQL translation我无法理解 HQL 到 SQL 的翻译
【发布时间】:2018-02-15 20:30:26
【问题描述】:

为什么我的简单 List<Shopping> products = session.createQuery("FROM Shopping").list(); 给出以下错误:

java.sql.SQLException:“字段列表”中的未知列“shopping0_.product”

这里是映射文件 Shopping.hbm.xml

<?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>

表格是:

+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| basketid | int(11)     | NO   | PRI | NULL    |       |
| product  | varchar(30) | NO   | PRI | NULL    |       |
| quantity | int(11)     | NO   |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+

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

【问题讨论】:

  • name="productID" 确实将其更改为 name="product" 会有所不同
  • 否,因为类中的字段是String productID。
  • 还显示实体类,对于这个表和它关联的任何实体类
  • 对不起,我应该发布 itclass Shopping implements Serializable { private int basketID;私有字符串产品ID;私有 int 数量;公共购物(){数量=1; } public int getBasketID() { 返回购物篮ID; } public String getProductID() { return productID; } public int getQuantity() { 返回数量; } 公共无效 setBasketID(int basketID) { this.basketID=basketID; } public void setProductID(String productID) { this.productID=productID; } public void setQuantity(int quantity) { this.quantity=quantity; } }

标签: java hibernate mariadb hql


【解决方案1】:

基于错误 - 该表没有产品列。它被称为 productId 吗?另外,您是否有在 hbm 文件中定义的复合键,在您的数据库中 - 在 basketid 和 product 上。

【讨论】:

    【解决方案2】:

    如果 basketid 和 product 是外键,那么您需要更改 HBM 映射,因为我在 hbm 中没有看到映射。

    【讨论】:

      猜你喜欢
      • 2014-03-10
      • 1970-01-01
      • 2016-01-15
      • 2021-06-08
      • 2011-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-18
      相关资源
      最近更新 更多