Reputation: 99
I want to iterate through an sql table using JPA, example of use:
I have the table Person which contains 100 columns
id | gender | firstname | lastname | address1 | address2 | number | ....+100
------------------------------------------------------------------------------
- | ... | ..... | ... | .... | .... | .. | ....
------------------------------------------------------------------------------
- | ... | ..... | ... | .... | .... | .. | ....
and in my Java program, I want to do the following (as an example):
the problem is that I don't want to create an Entity class of Person because it contains 100 columns and it's quite cumbersome and I'm not interested with all of them.
Also, I don't want to retrieve the row in an Object[] type, because suppose that I want to extract 40 columns out of 100, it will be confusing to manipulate such a type.
I'm using spring data JPA and not JDBC.
Upvotes: 0
Views: 769
Reputation: 544
You can create an entity class with only the columns you're interrested in.
And then, with Spring data, you will get a collection of Person class which you can iterate through the way you like.
Upvotes: 1