Product Class
@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;
}
}
Query Function:
@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;
}
In the above function, the print out is correct in the number of rows but all the rows are showing the data of the first row. Any ideas?
PS: Using Sybase
ticket
is the ID (i.e. the primary key) of the product entity. There should be only one product with a given ticket in database. If there's more than one, then your mapping or your database model is wrong.
精彩评论