NullPointerException while searching in DB

2019-09-04 18:38发布

I have the following entity, Customer:

@Entity
@Table(name = "customer")
@NamedQueries({
@NamedQuery(name = "**Customer.findByEmail**", query = "SELECT c FROM Customer c WHERE c.email = :email"),
(...)

And the following session facade method:

public List<Customer> GetPorEmail(String match){
    List customers = em.createNamedQuery("Customer.findByEmail").setParameter("email", match).getResultList();     
    return customers;
}

When I call the method, the result is always java.lang.NullPointerException.

I am certain that there are emails matching the match in my DB.

How is this caused and how can I solve it?

标签: jpa
1条回答
太酷不给撩
2楼-- · 2019-09-04 19:30

I think your EntityManager is null. Please check whether you are injecting EntityManager reference properly and its not null.

Regards,

查看更多
登录 后发表回答