在数据库中搜索时,EntityManager为null和NullPointerException [英] EntityManager null and NullPointerException while searching in DB
问题描述
我真的是Java ee的菜鸟
i am really noob in java ee
我要查询以确认电子邮件是否唯一
i want to make a query to verify if email is unique
在网上搜索后,我很生气,得出的结论是我的EntityManeger为空
after i search on web i mad i came to conclusion that me EntityManeger is null
这是我的实体客户,是一个查询 Customer.findByEmail ,这是我的关注点
this is my entity Customer and is an query Customer.findByEmail that is my point of focus
@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的会话
i have a session named 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();
}
如何避免实体管理器中的为空
Whats the solution to avoid null in entity manager
推荐答案
确保您正在Java EE服务器上运行并通过容器访问SessionBean.
Ensure you are running in a Java EE server and accessing the SessionBean through the container.
您在哪台服务器上运行?您如何访问SessionBean?
What server are you running in? How do you access the SessionBean?
这篇关于在数据库中搜索时,EntityManager为null和NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!