HibernateTemplate.find返回正确的行数但具有相同的数据

时间:2011-08-12 08:04:44

标签: java hibernate

产品类

@Entity
@Table (name="product")

public class Productimplements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private Date date;
    private String type;
    private Integer ticket;

    @Id
    @Column (name="ticket")
    public Integer getTicket() {
        return ticket;
    }
    public void setTicket(Integer ticket) {
        this.ticket = ticket;
    }


    @Column (name="date")
    public Date getDate() {
        return date;
    }
    public void setDate(Date date) {
        this.date = date;
    }

    @Column (name="type")
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
}

查询功能:

@SuppressWarnings("unchecked")
    @Override
    public List<Product> getProductByTicket(Integer ticket) {
        Object [] params = new Object [] {ticket};
        String hql = "from Product as p where p.ticket = ?";

        List <Product> productList = hibernateTemplate.find(hql, params);

        for (Product i: productList) {
            System.out.printf ("DATE = %s TYPE = %s\n", i.getDate(), i.getType());
        }
        return productList;
    }

在上述功能中,打印输出的行数是正确的,但所有行都显示第一行的数据。有什么想法吗?

PS:使用Sybase

1 个答案:

答案 0 :(得分:2)

ticket是产品实体的ID(即主键)。在数据库中应该只有一个具有给定票证的产品。如果有多个,那么您的映射或数据库模型是错误的。