我正在学习 Entity Bean,但在进行实验室时出现此错误。我选择为 Entity 类(对于 Entity Product
)创建一个 Session Bean。此文件由 NetBeans 自动创建。但它告知ProductsFacade.java uses unchecked or unsafe operations.
这是代码:
@Stateless
public class ProductsFacade implements ProductsFacadeRemote {
@PersistenceContext(unitName = "NhungBHSE02082_SE0606_AdvJava_Lab10_11-ejbPU")
private EntityManager em;
public void create(Products products) {
em.persist(products);
}
public void edit(Products products) {
em.merge(products);`enter code here`
}
public void remove(Products products) {
em.remove(em.merge(products));
}
public Products find(Object id) {
return em.find(Products.class, id);
}
public List<Products> findAll() {
return em.createQuery("select object(o) from Products as o").getResultList();
}
public List<Products> findRange(int[] range) {
Query q = em.createQuery("select object(o) from Products as o");
q.setMaxResults(range[1] - range[0]);
q.setFirstResult(range[0]);
return q.getResultList();
}
public int count() {
return ((Long) em.createQuery("select count(o) from Products as o").getSingleResult()).intValue();
}
}