org.hibernate.exception.DataException: could not execute query
Stringlimit="selectcpro.productIdfromCategoryProductcprowherecpro.catId=?";StringhqlP...
String limit = "select cpro.productId from CategoryProduct cpro where cpro.catId=? ";
String hqlPro = "select bo from Book bo where bo.id=(select id from Product)";
List<Integer> list = getSession().createQuery(limit).setParameter(0, Integer.parseInt(cid))/*.setParameter(1, page).setParameter(2, size)*/.list();
System.out.println(getSession().createQuery(hqlPro).list());
List<Product> listPro = null ;
return listPro;
那里出现问题了?
CREATE TABLE product (
id int(12) NOT NULL auto_increment,
product_name varchar(100) NOT NULL,
description varchar(100) default NULL,
add_time bigint(20) default NULL,
fixed_price double NOT NULL,
dang_price double NOT NULL,
keywords varchar(200) default NULL,
has_deleted int(1) NOT NULL default '0',
product_pic varchar(200) default NULL,
PRIMARY KEY (id)
)
CREATE TABLE book (
id int(12) NOT NULL,
author varchar(200) NOT NULL,
publishing varchar(200) NOT NULL,
publish_time bigint(20) NOT NULL,
word_number varchar(15) default NULL,
which_edtion varchar(15) default NULL,
total_page varchar(15) default NULL,
print_time int(20) default NULL,
print_number varchar(15) default NULL,
isbn varchar(25) default NULL,
author_summary text NOT NULL,
catalogue text NOT NULL,
PRIMARY KEY (id)
)
CREATE TABLE category (
id int(12) NOT NULL auto_increment,
turn int(10) NOT NULL,
en_name varchar(200) NOT NULL,
name varchar(200) NOT NULL,
description varchar(200),
parent_id int(10),
PRIMARY KEY (id)
)
CREATE TABLE category_product (
id int(12) NOT NULL auto_increment,
product_id int(10) NOT NULL,
cat_id int(10) NOT NULL,
PRIMARY KEY (id)
) 展开
String hqlPro = "select bo from Book bo where bo.id=(select id from Product)";
List<Integer> list = getSession().createQuery(limit).setParameter(0, Integer.parseInt(cid))/*.setParameter(1, page).setParameter(2, size)*/.list();
System.out.println(getSession().createQuery(hqlPro).list());
List<Product> listPro = null ;
return listPro;
那里出现问题了?
CREATE TABLE product (
id int(12) NOT NULL auto_increment,
product_name varchar(100) NOT NULL,
description varchar(100) default NULL,
add_time bigint(20) default NULL,
fixed_price double NOT NULL,
dang_price double NOT NULL,
keywords varchar(200) default NULL,
has_deleted int(1) NOT NULL default '0',
product_pic varchar(200) default NULL,
PRIMARY KEY (id)
)
CREATE TABLE book (
id int(12) NOT NULL,
author varchar(200) NOT NULL,
publishing varchar(200) NOT NULL,
publish_time bigint(20) NOT NULL,
word_number varchar(15) default NULL,
which_edtion varchar(15) default NULL,
total_page varchar(15) default NULL,
print_time int(20) default NULL,
print_number varchar(15) default NULL,
isbn varchar(25) default NULL,
author_summary text NOT NULL,
catalogue text NOT NULL,
PRIMARY KEY (id)
)
CREATE TABLE category (
id int(12) NOT NULL auto_increment,
turn int(10) NOT NULL,
en_name varchar(200) NOT NULL,
name varchar(200) NOT NULL,
description varchar(200),
parent_id int(10),
PRIMARY KEY (id)
)
CREATE TABLE category_product (
id int(12) NOT NULL auto_increment,
product_id int(10) NOT NULL,
cat_id int(10) NOT NULL,
PRIMARY KEY (id)
) 展开
展开全部
那是自动回答的
1: HQL 没有select ******** 的,直接 from ObjectName where ************
2: select bo from Book bo where bo.id=(select id from Product)
应该写成 from Book bo where bo.id=(select id from Product)
另外select id from Product 这个语句返回的应该是集合,所以前面的bo.id = 就有问题,应该用in
如: from Book bo where bo.id in (select id from Product)
1: HQL 没有select ******** 的,直接 from ObjectName where ************
2: select bo from Book bo where bo.id=(select id from Product)
应该写成 from Book bo where bo.id=(select id from Product)
另外select id from Product 这个语句返回的应该是集合,所以前面的bo.id = 就有问题,应该用in
如: from Book bo where bo.id in (select id from Product)
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询