2

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

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?)

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.

What are your thoughts on this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
SoftwareSavant
  • 9,467
  • 27
  • 121
  • 195

2 Answers2

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

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

Thanks for the help and inspiration guys.

SoftwareSavant
  • 9,467
  • 27
  • 121
  • 195
1

Suppose a Category has many products:

select product.name from Category c inner join c.products product where ...

If that's not what you want, please show an example in your question.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255