我在java ee中真的很棒
我想进行查询以验证电子邮件是否唯一
我在网上搜索后,我得出结论,我的EntityManeger为空
这是我的实体客户,是一个查询 Customer.findByEmail ,这是我的关注点
@Entity
@Table(name = "customer")
@NamedQueries({
@NamedQuery(name = "Customer.findAll", query = "SELECT c FROM Customer c"),
@NamedQuery(name = "Customer.findById", query = "SELECT c FROM Customer c WHERE c.id = :id"),
@NamedQuery(name = "Customer.findByName", query = "SELECT c FROM Customer c WHERE c.name = :name"),
@NamedQuery(name = "Customer.findByEmail", query = "SELECT c FROM Customer c WHERE c.email = :email"),
(...)
我有一个名为CutomerFacade的会话
@Stateless
public class CustomerFacade extends AbstractFacade<Customer> {
@PersistenceContext(unitName = "AffableBeanPU")
public EntityManager em;
public List<Customer> GetPorEmail(String match){
return em.createNamedQuery("Customer.findByEmail").setParameter("email", match).getResultList();
}
解决方案是避免在实体管理器中 null
答案 0 :(得分:0)
确保您在Java EE服务器中运行并通过容器访问SessionBean。
你在运行什么服务器?你如何访问SessionBean?