我可以在JPA实体内执行查询以返回单个列 [英] can I perform a query inside of JPA entity to get back a single column

查看:703
本文介绍了我可以在JPA实体内执行查询以返回单个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个愚蠢的问题.如果可以做到,那就太好了,但我没有屏住呼吸.

I have a dumb question. It would be great if this could be done, but I am not holding my breath.

我需要链接到我的JPA实体的表中的单个列作为所述JPA实体中的集合.有什么办法,我可以只取回与该实体相关的那一列,而不必取回整个表(这可能会非常昂贵?)

I need a single column from a table linked to my JPA entity to be a collection in said JPA entity. Is there any way, that I can just get back that column alone that is related to that entity, instead of having to get back an entire table (which could be very costly?)

我可以在该JPA实体内执行查询,该查询将被执行并急切地加载到集合中吗?

Can I perform a query inside that JPA entity that will be performed and loaded eagerly into a collection?

我试图通过仅执行几个查询来避免不得不多次调用数据库.

I am trying to avoid having to make several calls to the database by just executing a couple of queries.

您对此有何看法?

推荐答案

@ElementCollection(fetch=FetchType.EAGER)
        @CollectionTable(name="QUICK_LAUNCH_DISTLIST",joinColumns=@JoinColumn(name="QUICK_LAUNCH_ID"))
        @Column(name="LIST_ID")
private List<Long> distListIDs;

我正在寻找ElementCollection属性.除此之外,它看起来还不错.

The ElementCollection attribute is what I was looking for. It seems to work pretty well in addition to that.

感谢帮助和启发的人.

这篇关于我可以在JPA实体内执行查询以返回单个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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