在数据库中搜索时发生NullPointerException

在数据库中搜索时发生NullPointerException

本文介绍了在数据库中搜索时发生NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下实体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;
}

当我调用该方法时,结果始终为java.lang.NullPointerException.

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

我确定我的数据库中有匹配match的电子邮件.

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

这是怎么引起的,我该如何解决?

How is this caused and how can I solve it?

推荐答案

我认为您的EntityManager为null.请检查您是否正确注入了EntityManager引用,并且引用不为null.

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

此致

这篇关于在数据库中搜索时发生NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 09:06