从我的数据库中提取数据时遇到问题,它有大约600万条记录。这是一个Web应用程序,然后tomcat日志返回GC限制超出。
其他解决方案是分页然后我们查询的每个页面。
也许还有一些其他技巧/解决方法。
它有2个联合列,也是对象。
public class PricesRaw {
@Id
@GeneratedValue
@Column(name = "price_raw_id")
private int price_raw_id;
@Column(name = "date")
private Date date;
@Column(name = "year")
private int year;
@Column(name = "size")
private int size;
@Column(name = "stock")
private int stock;
@Column(name = "price")
private double price;
@Column(name = "idccy")
private int ccy;
@Column(name = "status")
private int status;
@ManyToOne
@JoinColumn(name = "idwine")
private Wine wine;
@ManyToOne
@JoinColumn(name = "idmerchant")
private Merchant merchant;
public PricesRaw(){}
public PricesRaw(Date date, int year, int size, int stock, Double price,
int idccy, int status, Wine idWine, Merchant idMerchant)
{
this.date = date;
this.year = year;
this.size = size;
this.stock = stock;
this.price = price;
this.ccy = idccy;
this.status = status;
this.wine = idWine;
this.merchant = idMerchant;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getCcy() {
return ccy;
}
public void setCcy(int ccy) {
this.ccy = ccy;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public Wine getWine() {
return wine;
}
public void setWine(Wine wine) {
this.wine = wine;
}
public Merchant getMerchant() {
return merchant;
}
public void setMerchant(Merchant merchant) {
this.merchant = merchant;
}
} 这是我的hibernate被称为。我对Hibernate的新手还在探索它的功能,我们非常感谢任何技术
public List<PricesRaw> getPrices()
{
Criteria criteria = getSession().createCriteria(PricesRaw.class);
// Problem is here.
return (List<PricesRaw>) criteria.list();
}
答案 0 :(得分:0)
是的Saul我们在实时应用程序中遇到了这种问题。但就技术而言,我们有两种方法可以完成它。
要在代码下方使用延迟加载。
public List<PricesRaw> getPrices() {
Criteria criteria = getSession().createCriteria(PricesRaw.class);
criteria.setFirstResult(first);
criteria.setMaxResults(pageSize);
return (List<PricesRaw>) criteria.list();
}
通过这种方式,您可以在tomcat中保存自己GC Limit exceeded
以及内存不足。
希望这会对你有帮助!