Request partial objects with JPA

I have a JPA object similar to;

public class Inventory {
 private String productname;
 private String manufacturer;
 private Float retailprice;
 private Integer unitssold;
 private String ourcomment;
}

In about 2 out of 5 queries, I need the whole object, but the rest of the time I'm not interested in units and our comment.

It looks like a waste to make a request and get a large list of results, but only 3/5 of the information. I would like to optimize this a bit, and I have a hunch that this can be done using inheritance.

But how?

+3
source share
2 answers

Inheritance? No.

, , , Inventory , , , ( , ) - .

, 4- 5- ""; JPA -, :

@Basic(fetch = FetchType.LAZY)
private Integer unitssold;

@Basic(fetch = FetchType.LAZY)
private String ourcomment;

fetch all properties , ; .

, , , "" (, Integer; String , )

+4

, , .

0

Source: https://habr.com/ru/post/1716533/


All Articles