Reputation: 869
I have a big table that has many columns. In different use cases I need to load different columns from this table, but usually I don't need all of the columns. So now I think I should select the necessary columns from this big table.
For example I have a simple POJO like UseCase1 and I use this named query:
SELECT NEW UseCase1(t.a, t.b, t.c) FROM MyBigTable t
In update statements I also update only a, b, c fields.
So the question is, this is a good solution, to improve performance if I can't change the table? And will this improve the performance? :)
Upvotes: 1
Views: 1637
Reputation: 1535
You can also lazy-load individual non-relation fields (e.g. Strings) by using @Basic(fetch = LAZY), e.g.
@Basic(fetch = LAZY)
private String description;
The table column for this field will not be loaded. Be careful that when you DO access the field that it will be lazy loaded with a single query which has the potential to become a different performance problem (N+1 select).
Upvotes: 0
Reputation: 11839
We had similar situations, and you can see the performance improvement using this technique in 2 cases.
Like @JB told, when we speak about performance nothing can be finalized without measuring it.These 2 point were my general experiences.
Upvotes: 1