0

我真的是java ee的菜鸟

我想查询以验证电子邮件是否唯一

在我在网上搜索后,我很生气,我得出的结论是我的 EntityManeger 是空的

这是我的实体 Customer并且是一个查询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 的解决方案是什么

4

1 回答 1

0

确保您在 Java EE 服务器中运行并通过容器访问 SessionBean。

你在什么服务器上运行?您如何访问 SessionBean?

于 2013-04-15T13:09:59.497 回答