这个是实体类:package com.kfdou.faxian.entity.shop;import java.util.Date;
import java.util.List;import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;import com.kfdou.faxian.entity.IdEntity;/**
 * 用户.
 * 
 * 使用JPA annotation定义ORM关系.
 * 使用Hibernate annotation定义JPA 1.0未覆盖的部分.
 * 
 * @author calvin
 */
@Entity
//表名与类名不相同时重新定义表名.
@Table(name = "finditem")
//默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Finditem extends IdEntity { public Finditem() {
// TODO Auto-generated constructor stub
}



public Finditem(Long id,int friendconcern,String name, String address, double oldprice,
double discount,Date findtime,String itemintro,User user) {
super();
this.id = id;
this.friendconcern = friendconcern;
this.name = name;
this.address = address;
this.oldprice = oldprice;
this.discount = discount;
this.findtime = findtime;
this.user = user;
this.itemintro = itemintro;
} //发现类型

private Findtype findtype;

//商品类型
private Itemtype itemtype;

//全部好友关注度
private int friendconcern; 

//名字
private String name;

//地址
private String address;

//价格
private double price;

//原价
private double oldprice;

//折扣
private double discount;

//用户
private User user;

//介绍
private String itemintro;

//发现日期
private Date findtime; //图片
private List<Picture> pictures;

//评价
private List<Evaluation> evaluations;

//评论
private List<FindComments> findcomments;

//标签
private List<ItemTag> itemTags;

@JoinColumn(name = "itemid")
@OneToMany()
public List<ItemTag> getItemTags() {
return itemTags;
}

public void setItemTags(List<ItemTag> itemTags) {
this.itemTags = itemTags;
}

public void setFindcomments(List<FindComments> findcomments) {
this.findcomments = findcomments;
}

@JoinColumn(name = "itemid")
@OneToMany
public List<FindComments> getFindcomments() {
return findcomments;
}



public void setEvaluations(List<Evaluation> evaluations) {
this.evaluations = evaluations;
}

@JoinColumn(name = "itemid")
@OneToMany
public List<Evaluation> getEvaluations() {
return evaluations;
}

public void setPictures(List<Picture> pictures) {
this.pictures = pictures;
}

@JoinColumn(name = "itemid")
@OneToMany
public List<Picture> getPictures() {
return pictures;
}

@JoinColumn(name = "fid")
@ManyToOne()
public Findtype getFindtype() {
return findtype;
}
public void setFindtype(Findtype findtype) {
this.findtype = findtype;
} @JoinColumn(name = "itemttypid")
@ManyToOne()
public Itemtype getItemtype() {
return itemtype;
}
public void setItemtype(Itemtype itemtype) {
this.itemtype = itemtype;
}
public int getFriendconcern() {
return friendconcern;
} public void setFriendconcern(int friendconcern) {
this.friendconcern = friendconcern;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getAddress() {
return address;
} public void setAddress(String address) {
this.address = address;
} public double getPrice() {
return price;
} public void setPrice(double price) {
this.price = price;
} public double getOldprice() {
return oldprice;
} public void setOldprice(double oldprice) {
this.oldprice = oldprice;
} public double getDiscount() {
return discount;
} public void setDiscount(double discount) {
this.discount = discount;
} @JoinColumn(name = "userid")
@ManyToOne()
public User getUser() {
return user;
} public void setUser(User user) {
this.user = user;
} public String getItemintro() {
return itemintro;
} public void setItemintro(String itemintro) {
this.itemintro = itemintro;
} public Date getFindtime() {
return findtime;
} public void setFindtime(Date findtime) {
this.findtime = findtime;
} @Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}

解决方案 »

  1.   

    这个是分页查询的方法
    public Page<Finditem> getItemByPage(Page<Finditem> page){
    return findDao.findPage(page, 
    "select new Finditem(f.id,f.friendconcern,f.name, f.address, f.price, f.oldprice, " +
    "f.findtime," +
    " f.itemintro, f.user) from Finditem f order by f.findtime desc");
    }这样写hql是没有问题的,我现在只要查询一部分数据,所以用了new Finditem()写法,我现在要做的是把集合pictures放进去,构造函数写成如下:public Finditem(Long id,int friendconcern,String name, String address, double oldprice,
    double discount,Date findtime,String itemintro,User user,List<Picture> pictures) {
    super();
    this.id = id;
    this.friendconcern = friendconcern;
    this.name = name;
    this.address = address;
    this.oldprice = oldprice;
    this.discount = discount;
    this.findtime = findtime;
    this.user = user;
    this.itemintro = itemintro;
            this.pictures = pictures;
    }然后hql写成如下:public Page<Finditem> getItemByPage(Page<Finditem> page){

    return findDao.findPage(page, 
    "select new Finditem(f.id,f.friendconcern,f.name, f.address, f.price, f.oldprice, " +
    "f.findtime," +
    " f.itemintro, f.user,f.pictures) from Finditem f order by f.findtime desc");
    }
      

  2.   

    然后就报没有构造函数,报错如下:
    2011-06-16 17:36:49,256 [http-8080-5] ERROR [org.hibernate.hql.PARSER] -  Unable to locate appropriate constructor on class [com.kfdou.faxian.entity.shop.Finditem]
    [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.kfdou.faxian.entity.shop.Finditem]
    2011-06-16 17:36:49,293 [http-8080-5] ERROR [500.jsp] - Unable to locate appropriate constructor on class [com.kfdou.faxian.entity.shop.Finditem] [select new Finditem(f.id,f.friendconcern,f.name, f.address, f.price, f.oldprice, f.findtime, f.itemintro, f.user,f.pictures) from com.kfdou.faxian.entity.shop.Finditem f order by f.findtime desc]
    org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.kfdou.faxian.entity.shop.Finditem] [select new Finditem(f.id,f.friendconcern,f.name, f.address, f.price, f.oldprice, f.findtime, f.itemintro, f.user,f.pictures) from com.kfdou.faxian.entity.shop.Finditem f order by f.findtime desc]
    at 请指教我该如何写才能把List<Picture> 查询出来?
      

  3.   

    然后就报没有构造函数,2011-06-16 17:36:49,256 [http-8080-5] ERROR [org.hibernate.hql.PARSER] -  Unable to locate appropriate constructor on class [com.kfdou.faxian.entity.shop.Finditem]
    [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.kfdou.faxian.entity.shop.Finditem]
    2011-06-16 17:36:49,293 [http-8080-5] ERROR [500.jsp] - Unable to locate appropriate constructor on class [com.kfdou.faxian.entity.shop.Finditem] [select new Finditem(f.id,f.friendconcern,f.name, f.address, f.price, f.oldprice, f.findtime, f.itemintro, f.user,f.pictures) from com.kfdou.faxian.entity.shop.Finditem f order by f.findtime desc]
    org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.kfdou.faxian.entity.shop.Finditem] [select new Finditem(f.id,f.friendconcern,f.name, f.address, f.price, f.oldprice, f.findtime, f.itemintro, f.user,f.pictures) from com.kfdou.faxian.entity.shop.Finditem f order by f.findtime desc]
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
      

  4.   

    public Finditem(Long id,int friendconcern,String name, String address, double oldprice,
                double discount,Date findtime,String itemintro,User user,List<Picture> pictures) {
            super();
            this.id = id;
            this.friendconcern = friendconcern;
            this.name = name;
            this.address = address;
            this.oldprice = oldprice;
            this.discount = discount;
            this.findtime = findtime;
            this.user = user;
            this.itemintro = itemintro;
            this.pictures = pictures;
        }
    这个构造函数里少了一个price吧,sql语句里有,构造函数里没有的字段,你加上看看
      

  5.   


    public Finditem(Long id,int friendconcern,String name, String address, double price,double oldprice,
    double discount,Date findtime,String itemintro,User user,List<Picture> pictures) {
    super();
    this.id = id;
    this.friendconcern = friendconcern;
    this.name = name;
    this.address = address;
    this.price = price;
    this.oldprice = oldprice;
    this.discount = discount;
    this.findtime = findtime;
    this.user = user;
    this.itemintro = itemintro;
    //this.pictures = pictures;
    }public Page<Finditem> getItemByPage(Page<Finditem> page){

    return findDao.findPage(page, 
    "select new Finditem(f.id,f.friendconcern,f.name, f.address, f.price, f.oldprice, " +
    "f.discount,f.findtime," +
    " f.itemintro, f.user,f.pictures) from Finditem f order by f.findtime desc");
    }嗯,谢谢,改了之后还是报错,去掉List<Picture> pictures,和f.pictures就不会报错。