2017-03-24 14:42:27,943 ERROR [edu.ur.ir.web.action.item.GovernmentAction] 系统抛出异常!java.math.BigInteger cannot be cast to java.lang.Long
源代码:
public Long getCollectionId(Long governmentId) {
String sql = "select ir_item.crawler_configure.institutional_collection_id as id from ir_item.government LEFT JOIN "
+ "ir_item.crawler_configure on ir_item.government.government_crawlerconfigure_id = ir_item.crawler_configure.configure_id "
+ "where ir_item.government.government_id="+governmentId;
Long id = (Long) hbCrudDAO.getSessionFactory().getCurrentSession().createSQLQuery(sql)
.uniqueResult();
return id;
}
修改后的代码(1):
public Long getCollectionId(Long governmentId) {
String sql = "select ir_item.crawler_configure.institutional_collection_id as id from ir_item.government LEFT JOIN "
+ "ir_item.crawler_configure on ir_item.government.government_crawlerconfigure_id = ir_item.crawler_configure.configure_id "
+ "where ir_item.government.government_id="+governmentId;
Long id = (Long) hbCrudDAO.getSessionFactory().getCurrentSession().createSQLQuery(sql)
.addScalar("id",Hibernate.LONG)
.uniqueResult();
return id;
}
修改后的代码(2):
public Long getCollectionId(Long governmentId) {
String sql = "select ir_item.crawler_configure.institutional_collection_id as id from ir_item.government LEFT JOIN "
+ "ir_item.crawler_configure on ir_item.government.government_crawlerconfigure_id = ir_item.crawler_configure.configure_id "
+ "where ir_item.government.government_id="+governmentId;
BigInteger id = (BigInteger) hbCrudDAO.getSessionFactory().getCurrentSession().createSQLQuery(sql)
.uniqueResult();
return id.longValue();
}