0
我使用Spring & Hibernate,我想在他的DAO中使用他的id来获得产品。Spring Hibernate - Dao返回ID
@Repository
@Transactional
public class ProductDaoImpl implements ProductDao {
protected final Log logger = LogFactory.getLog(getClass());
@Autowired
private SessionFactory sessionFactory;
public List<Product> getProductList() {
return sessionFactory.getCurrentSession().createQuery("from Product p order by p.productName asc").list();
}
public Product getProductById(int productId) {
String hql = "from Product p where p.productId = :id";
Query query = sessionFactory.getCurrentSession().createQuery(hql);
query.setInteger("id", productId);
return null;
}
}
例如,当我想获得我的产品我回报他们的列表(调用函数getProductList()),但现在我想打电话给getProductById但我不知道我可以如何与返回的东西“产品”类型。
谢谢。