EntityManager null and NullPointerException while searching in DB

…衆ロ難τιáo~ 提交于 2019-12-11 18:37:22

问题


i am really noob in java ee

i want to make a query to verify if email is unique

after i search on web i mad i came to conclusion that me EntityManeger is null

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"),
(...)

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


回答1:


Ensure you are running in a Java EE server and accessing the SessionBean through the container.

What server are you running in? How do you access the SessionBean?



来源:https://stackoverflow.com/questions/16006320/entitymanager-null-and-nullpointerexception-while-searching-in-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!