public float findPriceByIsbn(String isbn) {
String hql="select b.price from Book b where b.isbn=?";
float price=(float)getSession().createQuery(hql).setString(0, isbn).uniqueResult();
return price;
}

在做类型强势转换拿时将要强制转换的类型写成一般的数据类型报错Cannot cast from Object to float,

后来改为

public float findPriceByIsbn(String isbn) {
String hql="select b.price from Book b where b.isbn=?";
float price=(Float)getSession().createQuery(hql).setString(0, isbn).uniqueResult();
return price;
}

在做强制转换时,float——>Float, int——>Integer

记录错误。

相关文章: