How to request only certain properties of an entity?

Viewed 61

I have created an entity, which stores details about invoices, such as when the invoice was created, its id, who it is for and so on. Now I am thinking about extending this entity with a property that stores the actual pdf as a byte array. I am not so sure, however, if this was a good idea, or whether it would be better to store the pdf in an extra entity.

In my frontend, I want to be able to send a GET request and retrieve all the invoice details, but not the actual pdfs. I also want to be able to select an invoice id in my frontend and then send a GET request to specifically download the pdf of the selected id. I am not really sure how to implement these two distinct GET request controllers, that's why I am thinking about creating a separate entity.

Can somebody explain to me what would be the better idea?

1 Answers

Use FetchType.LAZY. For example :

@Lob
@Basic(fetch=FetchType.LAZY)
@Column(name="my_data")
private byte[] data;
Related