产品类
@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
答案 0 :(得分:2)
ticket
是产品实体的ID(即主键)。在数据库中应该只有一个具有给定票证的产品。如果有多个,那么您的映射或数据库模型是错误的。