我不知道为什么我不能建造它?他们抛出此异常:org.hibernate.hql.ast.QuerySyntaxException:产品未映射[来自产品]
我的示例代码:
public Product[] searchProductByCatalog(String catalogid, String keyword) {
String sql = "from product where 1";
if (keyword.trim().equals("") == false) {
sql += " and product_name like '%" + keyword + "%'";
}
if (catalogid.trim().equals("-1") == false) {
sql += " and catalog_id = " + Integer.parseInt(catalogid);
}
try {
session.getTransaction().begin();
Query query = session.createQuery(sql);
List listProduct = query.list();
Product[] product = new Product[listProduct.size()];
listProduct.toArray(product);
session.flush();
session.getTransaction().commit();
return product;
} catch (Exception e) {
if (session.getTransaction().isActive()) {
session.getTransaction().rollback();
}
e.printStackTrace();
}
return null;
}
这是我的映射: 产品图谱:
<class name="pojo.Product" table="product" catalog="shoesshopdb">
<id name="idProduct" type="java.lang.Integer">
<column name="id_product" />
<generator class="assigned" />
</id>
<many-to-one name="catalog" class="pojo.Catalog" fetch="select" lazy="true">
<column name="catalog_id" />
</many-to-one>
<property name="productName" type="string">
<column name="product_name" length="45" />
</property>
<property name="date" type="date">
<column name="date" length="10" />
</property>
<property name="author" type="string">
<column name="author" length="45" />
</property>
<property name="price" type="java.lang.Integer">
<column name="price" />
</property>
<property name="linkimage" type="string">
<column name="linkimage" length="45" />
</property>
</class>
目录映射:
<class name="pojo.Catalog" table="catalog" catalog="shoesshopdb">
<id name="idCatalog" type="java.lang.Integer">
<column name="ID_CATALOG" />
<generator class="assigned" />
</id>
<property name="catalogName" type="string">
<column name="Catalog_Name" length="45" />
</property>
<set name="products" inverse="true">
<key>
<column name="catalog_id" />
</key>
<one-to-many class="pojo.Product" />
</set>
</class>
答案 0 :(得分:0)
班级名称为Product
,而不是product
。案件很重要。