有关JPA namedquery的怀疑 [英] Doubt regarding JPA namedquery

查看:115
本文介绍了有关JPA namedquery的怀疑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行一个namedquery

I am trying to execute a namedquery

@NamedQuery(name="getEmployeeDetails",query="select e.username,e.email,e.image,e.firstname,e.lastname from Employee e where e.empid=?1")

现在,当我在EJB 3.0会话Bean中执行此查询时,我应该返回什么对象.我尝试返回Listits返回一个向量,该向量会创建类广播异常.employee表包含诸如密码和其他我不知道的机密详细信息之类的字段不想获取.因此我不使用select e from Employee e. 我正在学习JPA,任何人都可以帮忙.

Now when I execute this query in a EJB 3.0 Session Bean what is the object I should return.I tried returning Listits returning a Vector which creates a classcast exception.The employee table contains fields like password and other confidential details which I don't want to fetch.So I am not using select e from Employee e. I am learning JPA can anyone help.

推荐答案

下面是示例查询,该查询仅获取必填字段,但必须为其创建此类构造函数.

Below is the sample query which fetches only the required fields, but have to make such constructor for it.

查询:SELECT NEW package_name.Employee(e.username,e.email,e.image,e.firstname,e.lastname) FROM Employee e where e.empid=?1;

它将返回具有选定字段&的Employee实体其余的将具有默认值.

It will return Employee entity with selected fields & remaining will have default values.

这篇关于有关JPA namedquery的怀疑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆